session-manager: race when creating a device
Sometimes Pipewire does not create the nodes and ports for detected V4L2 devices.
The reason for this is a possible race between the
bound_id event and the
global message that are sent from the core to the session-manager when the device is created.
The session-manager calls
sm_media_session_create_object() to export the device object to the core. This sends a
create_object message to the core. The core creates the device object, assigns an ID, sends the ID via
bound_id event to the session-manager and registers the object in the registry, which sends the
global message to notify the session manager about the new global.
The session-manager assigns the ID from the
bound_id event to its own object, which allows it to recognize the object from the
global message at its own object. Any later updates to the device object are handled correctly.
As the event and the message are sent via separate connections, it might happen that the session-manager first handles the
global message and afterwards the
bound_id event. Therefore, it fails to recognize its own object and finally has two distinct objects with the same ID for the same device and any messages from the device object in the core are sent to the wrong object on the session-manager.
I am not sure how to fix this:
- Maybe the session-manager must not accept globals after it created an object and has not received the ID, yet.
- Maybe we need an additional message that allows the session manager to explicitly register an object after it has been created and it received the ID.
Any guidance or hints would be appreciated.