calzoneman / sync

Node.JS Server and JavaScript/HTML Client for synchronizing online media
Other
1.45k stars 235 forks source link

Unable to connect to sync server using client running under Node 15 #900

Closed Xaekai closed 3 years ago

Xaekai commented 3 years ago

I've discovered that socket.io-client running under Node 15 cannot establish a connection to CyTube.

#[ xaekai@spheromancer ]
#[ ~/src/oldsrc/ponkbot ]$ curl -i "https://zip.cytu.be:10453/socket.io/?EIO=3&transport=polling"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 101
Access-Control-Allow-Origin: *
Set-Cookie: io=995PvKgpGTZ5N1XyCsrK; Path=/; HttpOnly; SameSite=Strict
Date: Sun, 28 Feb 2021 17:32:00 GMT
Connection: keep-alive
Keep-Alive: timeout=5

98:0{"sid":"995PvKgpGTZ5N1XyCsrK","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":120000}
#[ xaekai@spheromancer ]
#[ ~/src/oldsrc/ponkbot ]$ DEBUG=* node tmp      
  socket.io-client:url parse https://zip.cytu.be:10453 +0ms
  socket.io-client new io instance for https://zip.cytu.be:10453 +0ms
  socket.io-client:manager readyState closed +0ms
  socket.io-client:manager opening https://zip.cytu.be:10453 +0ms
  engine.io-client:socket creating transport "websocket" +0ms
  engine.io-client:socket setting transport websocket +10ms
  socket.io-client:manager connect attempt will timeout after 20000 +10ms
  socket.io-client:manager readyState opening +0ms
ugh
  socket.io-client:manager connect attempt timed out after 20000 +20s
  engine.io-client:socket socket close with reason: "forced close" +20s
  engine.io-client:socket socket closing - telling transport to close +0ms
  socket.io-client:manager connect_error +2ms
  socket.io-client:manager cleanup +0ms
connect_error due to undefined
  socket.io-client:manager will wait 798ms before reconnect attempt +1ms
  socket.io-client:manager attempting reconnect +800ms
  socket.io-client:manager readyState closed +0ms
  socket.io-client:manager opening https://zip.cytu.be:10453 +0ms
  engine.io-client:socket creating transport "polling" +803ms
  engine.io-client:polling polling +0ms
  engine.io-client:polling-xhr xhr poll +0ms
  engine.io-client:polling-xhr xhr open GET: https://zip.cytu.be:10453/socket.io/?EIO=3&transport=polling&t=NVfiPVm&b64=1 +1ms
  engine.io-client:polling-xhr xhr data null +1ms
  engine.io-client:socket setting transport polling +10ms
  socket.io-client:manager connect attempt will timeout after 20000 +11ms
  engine.io-client:socket socket error {"type":"TransportError","description":{"code":"ERR_CRYPTO_OPERATION_FAILED"}} +2ms
  socket.io-client:manager connect_error +2ms
  socket.io-client:manager cleanup +0ms
connect_error due to xhr poll error
  socket.io-client:manager reconnect attempt error +1ms
  socket.io-client:manager will wait 2986ms before reconnect attempt +0ms
  engine.io-client:socket socket close with reason: "transport error" +1ms
  engine.io-client:polling transport not open - deferring close +12ms
^C
calzoneman commented 3 years ago
Error: Unable to load PFX certificate
    at Object.createSecureContext (node:_tls_common:333:17)
    at Object.connect (node:_tls_wrap:1601:48)
    at Agent.createConnection (node:https:130:22)
    at Agent.createSocket (node:_http_agent:323:26)
    at Agent.addRequest (node:_http_agent:274:10)
    at new ClientRequest (node:_http_client:314:16)
    at request (node:https:326:10)
    at XMLHttpRequest.send (/home/calvin/tmp/n15err/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js:495:17)
    at Request.create (/home/calvin/tmp/n15err/node_modules/engine.io-client/lib/transports/polling-xhr.js:268:9)
    at new Request (/home/calvin/tmp/n15err/node_modules/engine.io-client/lib/transports/polling-xhr.js:170:8)
calzoneman commented 3 years ago

The reason for the polling transport to fail is because it appears node.js changed the behavior of passing null into various SSL options.

If you change this line: https://github.com/socketio/engine.io-client/blob/3.5.x/lib/socket.js#L89

this.pfx = opts.pfx || null;

to default to undefined instead of null, then the polling transport begins working again under node 15.

There is still the question of why the websocket transport is failing first (in the example you sent me, it's trying to connect to websocket first and fallback to polling); I suspect the reason is probably similar but I haven't checked.

calzoneman commented 3 years ago

It looks like the above code would affect both transports. So this is an engine.io issue -- wonder if they'd accept a PR. 3.5 is an old version, but it was recently updated (Dec 2020).

calzoneman commented 3 years ago

Issue filed against engine.io-client: https://github.com/socketio/engine.io-client/issues/654