I'm developing transparent proxy extension and noticed the following misbehaviour:
When NETransparentProxyProvider starts, if there are existing connections that matches rules, apps with these connections will get error (-41 Protocol wrong type for socket) on write()/send() syscall.
This leads Apple SSH and node.js to consume 100% CPU because they want to write to socket and can’t, while not receiving read event with an error.
Steps to reproduce (on Big Sur):
- Run SSH to some server in the internet.
- Run NETransparentProxyProvider example from https://github.com/sfionov/expert-octo-chainsaw
- Press a key in SSH
- See that Apple SSH consumes 100% CPU in Activity monitor.
In Activity Monitor’s sample you may see thousands of selects and unsuccessful writes.
Usually socket error is processed in read event, not write event, so lack of read event with error on unusable socket confuses a lot. :(
node.js apps with libuv SSL sockets start consuming a lot of CPU too.
Is there any workaround? Or a way I could force this applications to close unusable sockets after network extension start?