Occasional missing alsa devices after boot
In my test setup, I have an internal sound card and a USB headset. While the internal sound card is known fairly early (from the device tree), the USB device is enumerated (more or less) at the time the Pipewire system starts up. It sometimes happens that only the internal sound card is recognized correctly. An overnight reboot cycle test showed a chance of about 50%.
Finally, I think I found the cause of this behavior in 'spa/plugins/alsa/alsa-udev.c'. When pipewire starts, it uses udev to enumerate all alsa cards currently present and then starts listening for udev events. To check if the udev change event for a device was already emitted, the SOUND_INITIALIZED flag is used (see 78-sound-card.rules for an explanation of this mechanism). It can now happen that at startup a device is enumerated for which the SOUND_INITIALIZED flag is not (yet) set and is therefore not added by pipewire. The next moment, udev fires the event and sets the SOUND_INITIALIZED flag. Since pipewire has no udev monitoring set up at this point, this event is lost and the device is never added (unless it is reconnected). Since the time span for this is quite short and the USB enumeration has to take place almost at the same time as pipewire is started, this problem can rarely occur. But once the system has 'perfect' timing, this problem will appear quite frequently.
For a quick test, I just called 'start_monitor()' before executing 'enum_devies()' in 'impl_device_add_listener()'. This means that events can no longer be lost. Running my endurance test with this change again showed a 100% success rate.
I used pipewire-0.3.43 for my tests, but it looks like the associated source line is still the same.