From c584335d44365520d14bc63abeaa48dd3da9a38f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 15 Oct 2025 18:40:11 +0300 Subject: [PATCH] bap: tolerate inverted STREAMING and iso_connect_cb() Ordering of STREAMING and iso_connect_cb() is unspecified, as kernel/Glib do not preserve the order of these events. STREAMING before iso_connect_cb() causes transport to fail Acquire() since bt_bap_stream_io::connecting == true. Fix by marking IO as connected even though the connection didn't yet complete. The socket fd is valid, although not yet writable/readable. Fixes: https://github.com/bluez/bluez/issues/1506 --- profiles/audio/bap.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 2994881cc..b776511c5 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -2874,6 +2874,27 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state, } break; case BT_BAP_STREAM_STATE_STREAMING: + /* Order of STREAMING and iso_connect_cb() is nondeterministic. + * + * If iso_connect_cb() did not complete yet, mark IO as + * connected regardless, otherwise transport fails acquiring it. + * If the connect doesn't actually succeed, it is handled via + * normal disconnect flow. + */ + if (setup) { + int fd; + + if (!setup->io || !setup->cis_active) + break; + if (!bt_bap_stream_io_is_connecting(stream, &fd)) + break; + if (fd != g_io_channel_unix_get_fd(setup->io)) + break; + + DBG("setup %p stream %p io not yet ready", + setup, stream); + bt_bap_stream_set_io(stream, fd); + } break; } } -- 2.47.3