For my case, it was making sure the effective firewall profile was all PRIVATE.
I have 4 connections on my machine, only one used, the others were connected to like another machine directly or something, It was not a defined network- so in my Firewall info page it said PRIVATE (active) PUBLIC (active). In other words both were applied.
How I fixed this is a bit out there, but make sure that you are on a PRIVATE network, or that the firewall settings are compatible.
I created Exceptions to Platformio.exe and pio.exe to allow. I created a loopback exception (conns to and from 127.0.0.0-127.255.255.255) are allowed.
Neither of those fixed it.
my specific error in the console was
mainThreadExtensionService.ts:64 RequestError: connect ECONNREFUSED 127.0.0.1:8011
at ClientRequest.<anonymous> (c:\Users\andyt\.vscode\extensions\platformio.platformio-ide-2.4.0\node_modules\got\dist\source\core\index.js:956:111)
at Object.onceWrapper (events.js:422:26)
at ClientRequest.emit (events.js:327:22)
at ClientRequest.EventEmitter.emit (domain.js:467:12)
at ClientRequest.origin.emit (c:\Users\andyt\.vscode\extensions\platformio.platformio-ide-2.4.0\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
at Socket.socketErrorListener (_http_client.js:469:9)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:467:12)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Expanding the errors with the dropdown shows the traceback:
_doInvokeHandler @ rpcProtocol.ts:472
_invokeHandler @ rpcProtocol.ts:457
_receiveRequest @ rpcProtocol.ts:373
_receiveOneMessage @ rpcProtocol.ts:295
(anonymous) @ rpcProtocol.ts:160
fire @ event.ts:577
fire @ ipc.net.ts:513
_receiveMessage @ ipc.net.ts:871
(anonymous) @ ipc.net.ts:710
fire @ event.ts:577
acceptChunk @ ipc.net.ts:286
(anonymous) @ ipc.net.ts:247
k @ ipc.net.ts:50
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188
Since RPC Features prominently in the call stack, I also allowed more of the RPC (Remote Procedure Call) related exceptions through the firewall, though ONLY on Private (e.g. on my home network- I could open it up everywhere, but its not really safe)
After tweaking the firewall, and then making sure the PRIVATE was the only active profile- the network I was connected to was defined as private, and the null connection was manually defined (169.254.x.x) and also declared PRIVATE.
This took off the PUBLIC firewall exceptions (block anything not specficially allowed) and allowed it to connect once again.
This issue has been plaguing me repeatedly for a few years now. And for me at least, I found the source- if one of the connections triggers a PUBLIC firewall policy- maybe wifi turns on, etc.) then nothing worked.
I tried all the other things, reinstalling (10x over the years) Python, path etc. And it was intermittent so really difficult to catch the source.