Hi Sebastian,
To understand what is happening exactly, we would need to understand the nature of the serial device with which you are communicating via Bonsai. Is it an Arduino? some other microcontroller? The behavior of the device will determine its robustness to serial port failures.
Also, in general I would separate the error behavior from successful termination. If successful termination is failing to close the port, indeed this should be investigated first (and deal with the error cases after).
In any case, if you could post a minimal workflow that reproduces this situation it would be really helpful for us to understand what is going on.
Hope this helps.