I play with my Arduino daily. And I get this error message at least once a day. I can upload 4 programs successfully and magically on the 5th time it happens. I run Arduino IDE 2.0.0 Beta.9
avrdude: ser_open(): can't set com-state for "\\.\COM3"
Upload error: Error: 2 UNKNOWN: uploading error: uploading error: exit status 1
I then go to Windows 10 --> device manager --> universal serial bus controllers --> and "update" drivers with the existing already installed driver --> restart my computer --> reorganize all my stuff after a reboot
Most of the time my quest ends there, but occasionally I have to pull the USB out and plug it back in for good measure. I've seen this error since 2015 in the forum (that thread was closed 4 years later with no real answer), but don't ever see a satisfactory answer that would fix this error so it never, ever, ever happens again.
I also have not determined the cause of this error. I have been collecting some references with the idea of eventually doing a survey to see whether I can find a good explanation or a pattern that will allow me to identify the cause, but I haven't found the time for it. Here is the list of links in case you want to take a look:
That is completely unrelated. The "Error: 2 UNKNOWN: exit status 1" is a very generic error message that only means something went wrong. There are a near infinite number of possible causes of this error message, so it shouldn't be used for correlation purposes. The more meaningful error message from the linked bug report is "undefined reference to `main'", whereas the one here is "can't set com-state". The one in the bug report is coming from the avr-gcc compiler, while this one is coming from the AVRDUDE uploader tool.