Skip to content

pulse-server: work around race condition in SET_DEFAULT/MOVE_*

P V requested to merge pvir/pipewire:pulse-move-fix into master

The default metadata update may be delayed for some time after SET_DEFAULT, since the session manager has to work on it.

MOVE_* commands need to know what the client thinks is the current default sink, so that they can decide between "move to default" and "move to specific device".

To avoid race condition here, stash the default value set by the client and use it in the MOVE_* commands, until the metadata update arrives.


See wireplumber#300

Race condition from logs:

[D][12818.642194] mod.protocol-pulse | [  pulse-server.c:  946 manager_metadata()] meta id:36 subject:0 key:default.audio.sink type:Spa:String:JSON value:{"name":"alsa_output.usb-Sony_Interactive_Entertainment_Wireless_Controller-00.analog-stereo"}
[I][12827.206836] mod.protocol-pulse | [  pulse-server.c: 4729 do_set_default()] [ZOOM VoiceEngine Loopback] SET_DEFAULT_SINK tag:47 name:zoomcombine
[I][12827.209165] mod.protocol-pulse | [  pulse-server.c: 4811 do_move_stream()] [ZOOM VoiceEngine Loopback] MOVE_SINK_INPUT tag:48 index:90 device:63 name:(null)
[I][12827.209404] mod.protocol-pulse | [  pulse-server.c: 4811 do_move_stream()] [ZOOM VoiceEngine Loopback] MOVE_SINK_INPUT tag:49 index:90 device:63 name:(null)
[I][12827.209599] mod.protocol-pulse | [  pulse-server.c: 4811 do_move_stream()] [ZOOM VoiceEngine Loopback] MOVE_SINK_INPUT tag:50 index:90 device:63 name:(null)
[D][12827.222708] mod.protocol-pulse | [  pulse-server.c:  946 manager_metadata()] meta id:36 subject:0 key:default.configured.audio.sink type:Spa:String:JSON value:{ "name": "zoomcombine" }
[D][12827.222736] mod.protocol-pulse | [  pulse-server.c:  946 manager_metadata()] meta id:36 subject:83 key:target.node type:Spa:Id value:-1
[D][12827.222746] mod.protocol-pulse | [  pulse-server.c:  946 manager_metadata()] meta id:36 subject:83 key:target.object type:Spa:Id value:-1

The default change and stream moves are done immediately after each other, and the metadata update is delayed, so pipewire-pulse redirected the stream to the default output instead of the intended target.

Edited by P V

Merge request reports