PlatformIO doesn't connect to the device on the first try

OS: Linux Mint 19.1
Board: ESP32 DevKitV4

Hello !

I have been noticing a strange issue for the past few days. Connecting to the serial port when trying to upload code or files doesn’t always work on the first try.
The error is pretty common:

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
*** [uploadfs] Error 2

I have also been encountering the same issue with the Serial Monitor. I have to open it twice or more times to get it to work.

I upload the code, then I start the Serial Monitor and it doesn’t work, and I have to try again.
Or, if I have the Serial Monitor already opened for the same code and I upload the code again, I have to restart the Serial Monitor to make it show some output.

I consider it an issue because it worked before. And I’m pretty sure I did not make any changes to VSC or PlatformIO.