Calling the flushInput flushOutput immediately after opening the port gave this problem also. Introducing 1 sec. sleep before flushing solved it for me.
Raspberrypi4 with arduino via usb is the serial port.