Remote device monitor crashes on first keypress

I’m trying to get remote development working with PlatformIO. I’ve successfully uploaded to my STM32 device using the remote upload command. Unfortunately the remote device monitor isn’t working.

The remote monitor connects successfully. I get the serial monitor window up in VSCode, and on the other machine I see the log message saying serial monitoring started and it’s using the correct COM port. As soon as I press a key, however, I get the following crash:

Unhandled Error
Traceback (most recent call last):
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/tcp.py", line 243, in doRead
    return self._dataReceived(data)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/tcp.py", line 249, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/device_monitor.py", line 33, in dataReceived
    self.factory.send_to_server(data)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/device_monitor.py", line 68, in send_to_server
    self.cdm.acwrite_data(data)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/device_monitor.py", line 222, in acwrite_data
    self._acwrite_buffer += data
builtins.TypeError: can only concatenate str (not "bytes") to str

Exception in thread rx:
Traceback (most recent call last):
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/urlhandler/protocol_socket.py", line 171, in read
    raise SerialException('socket disconnected')
serial.serialutil.SerialException: socket disconnected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner

--- exit ---
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/tools/miniterm.py", line 499, in reader
    data = self.serial.read(self.serial.in_waiting or 1)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/urlhandler/protocol_socket.py", line 178, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: socket disconnected

I wasn’t able to find any existing topics on this. Anyone encountered this before and know what might be wrong?

Might be a Python 3.9 incompatibility.

Pert bug to the core at Issues · platformio/platformio-core · GitHub.

Bug opened: Remote device monitor crashes on first keypress · Issue #4068 · platformio/platformio-core · GitHub