Weird behavior Closing and opening serial Port in Windows. Bug?

Hello I am trying to close and reopening a serial port in Windows ( CP210x) and it is not possible.

This is some pretty simple code:

  case '9': 
    println("pre-serial: "+serial);
      serial.clear();
      serial.stop();
      //serialPort.closePort();
      delay(1000);
      println("mid-serial: "+serial);
      
      synched=false;
      serial = new Serial(this, serialPort, BaudRate);
      println("post-serial: "+serial);
    break;

And this is the output:

It will never recover communications again, since after closing the port and reopening the serial.available() is zero.
On the other hand, I have tested a simple C program and it is working as expected, this issue only happens with Processing.

Is there an error on the Library?
Thank you

It seems the stop is done correctly, because if I try to open then the port with another application it works, but processing is unable to open it again.

Is it a library issue or can we modify something at sketch level?
Thank you

Hello @PAk ,

Some code I used to explore this:

// Example by Tom Igoe

import processing.serial.*;
Serial serial;  // The serial port
String comPort;
int BAUD = 9600;

boolean synched;

void setup() 
  {
  size(400, 300);
  // List all the available serial ports:
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  comPort = Serial.list()[4];
  serial = new Serial(this, comPort, BAUD);
  //delay(1000);
  if (serial.active())
    {
    synched = true;
    println(synched);
    }
  
  textAlign(CENTER, CENTER);  
  textSize(48); //Max textSize set
  }

int hrtBeat;

void draw()
  {
  background(255);
  //heartbeat
  
  int timer = frameCount%30;
  
  if (timer == 0)
    {
    //println(hrtBeat);
    hrtBeat++; 
    }
  fill(0);
  text(hrtBeat, 200, 100-20);
    
  if( (timer == 0) && synched )
    {
    for (int i=0; i<16; i++)
      {
      serial.write(i);
      }
    serial.write('\r');
    serial.write('\n');
    
    println(frameCount, "Serial sending...");
    //text("Serial sending...", 200, 200-20); 
    }
     
  }
  
// Stop (s)
void keyPressed()
  {
  if (key == 's')
    {  
    serial.clear();
    serial.stop();
    println(serial.active());
    println("mid-serial: "+serial);       
    synched = false;
    }
  
// Restart (r)  
  if (key == 'r' && !serial.active())
    {
    printArray(Serial.list());
    serial = new Serial(this, comPort, BAUD);
    //delay(500);
    println(serial.active());
    println("post-serial: "+serial); 
    synched = true;
    }    
  }

I use W10 and Processing 4.01.

I was able to start stop the serial port with Processing to:

I do not have any devices with a CP210x to test.

:)