Auto Close Serial Monitor Not working

I am using PlatformIO(v 5.0.3) in VScode (v1.52.1)and I have set to close the serial monitor before uploading. However it’s not working. I am getting upload error as the serial port was not accessible. Has anyone else noticed this problem?? How can I fix that?

Which platformio.ini? Are you closing the serial monitor in VSCode or are you using an external program?

Here are the ini.file contents for my project:

[env:sparkfun_promicro16]
platform = atmelavr
board = sparkfun_promicro16
framework = arduino
build_type = debug
monitor_speed = 115200
; monitor_filters = log2file
lib_deps =
  # RECOMMENDED
  # Accept new functionality in a backwards compatible manner and patches
  sparkfun/SparkFun CCS811 Arduino Library @ ^2.0.1

I am using VSCode and in the platformio extension settings I have selected the “Auto Close Serial Monitor” option.