Defining USB_DUAL_SERIAL causes PlatformIO "Upload and Monitor" to fail

I recently raised this as an issue against platformio/platform-teensy on github. I am just wondering if anyone else has come across this or can offer any insights.

Running PlatformIO using vscode on a Linux system (Intel® Core™ i7-10700K CPU @ 3.80GHz × 16) and with default values for monitor_port (no override in platformio.ini), reports success but persistently connects the monitor port to the wrong USB CDC channel (02).

To overcome this problem I would normally override the monitor_port in platformio.ini to point at the correct consistently named port under /dev/serial/by-id.

lrwxrwxrwx 1 root root 13 Feb 23 10:29 usb-Teensyduino_Dual_Serial_12205920-if00 → …/…/ttyACM0
lrwxrwxrwx 1 root root 13 Feb 23 10:29 usb-Teensyduino_Dual_Serial_12205920-if02 → …/…/ttyACM1

In this case this is the first entry shown above ending in if00. This is the correct USB CDC channel number.
However, this then fails with a file not found error (ENOENT) when the “Upload and Monitor” command is issued. Manually issuing Upload followed by Monitor commands works.

There is also a less frequent issue in which channel 02 is processed by udev before channel 00. This results in the link targets being swapped. This means the names under /dev/serial/by-id have to be used rather than the /dev/ttyACMx names.

I am currently working on getting TeensyDebug working consistently under platformio. The code to reproduce this problem can be found here.

I think speed and number of cores of the intel i7 based system I am running might be contributing to the timing related issues that form part of this problem.