Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] audio: Fix stale AVDTP connecting state
@ 2026-09-30 10:12 Kun Ma
  2026-09-30 15:15 ` [BlueZ] " bluez.test.bot
  2026-09-30 15:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Kun Ma @ 2026-09-30 10:12 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Kun Ma

When a remote dual-role A2DP device reconnects autonomously, both sink
and source services transition to their respective CONNECTING states
upon AVDTP_SESSION_STATE_CONNECTING.

If the remote device only configures one direction (e.g. initiating a
stream from remote Source to local Sink), the unused direction's state
remains stuck in CONNECTING even after the underlying AVDTP session has
reached AVDTP_SESSION_STATE_CONNECTED.

Subsequently, when policy or userspace attempts to initiate audio
playback (e.g. via sink_connect() or source_connect()), the call fails
immediately with -EBUSY due to this stale CONNECTING state.

Fix this by only returning -EBUSY if the underlying AVDTP session is
actually still in AVDTP_SESSION_STATE_CONNECTING. In addition, check if
a stream already exists on that service to prevent concurrent stream
allocations while the session is connected.

Link: https://github.com/bluez/bluez/issues/2381
---
 profiles/audio/sink.c   | 6 +++++-
 profiles/audio/source.c | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/sink.c b/profiles/audio/sink.c
index 81d5a3a6b..3363f421f 100644
--- a/profiles/audio/sink.c
+++ b/profiles/audio/sink.c
@@ -281,7 +281,11 @@ int sink_connect(struct btd_service *service)
 	if (sink->connect_id > 0 || sink->disconnect_id > 0)
 		return -EBUSY;
 
-	if (sink->state == SINK_STATE_CONNECTING)
+	if (sink->state == SINK_STATE_CONNECTING &&
+	    sink->session_state == AVDTP_SESSION_STATE_CONNECTING)
+		return -EBUSY;
+
+	if (sink->stream)
 		return -EBUSY;
 
 	if (sink->stream_state >= AVDTP_STATE_OPEN)
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index 6be4de74e..54f9c4a4e 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -282,7 +282,11 @@ int source_connect(struct btd_service *service)
 	if (source->connect_id > 0 || source->disconnect_id > 0)
 		return -EBUSY;
 
-	if (source->state == SOURCE_STATE_CONNECTING)
+	if (source->state == SOURCE_STATE_CONNECTING &&
+	    source->session_state == AVDTP_SESSION_STATE_CONNECTING)
+		return -EBUSY;
+
+	if (source->stream)
 		return -EBUSY;
 
 	if (source->stream_state >= AVDTP_STATE_OPEN)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-30 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 10:12 [PATCH BlueZ] audio: Fix stale AVDTP connecting state Kun Ma
2026-09-30 15:15 ` [BlueZ] " bluez.test.bot
2026-09-30 15:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox