New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot set property 'readyState' of undefined #600
Comments
Hi @dominic12 ! Do you know which version of |
Hi @darrachequesne, i'm using ws@7.2.3. I know that these issues exist, but it was always a wrong usage of WS. |
That's weird. It might be due to the socketOnClose method being called twice, so the // https://github.com/websockets/ws/blob/7.2.4/lib/websocket.js#L834
this.removeListener('close', socketOnClose); Maybe: -- socket.on('close', socketOnClose);
++ socket.once('close', socketOnClose); Could fix your issue? Could you please open an issue in the ws repository? |
I can confirm, that the method is called twice. Sometimes, i also get an "failed: Invalid frame header" error back. However, additionally to this issue, i will create an issue in the WS Repo too. |
If i remove transports: ['websocket'] from my client, all seems to work perfectly. But i need to have that set, because of Google Flex Env restrictions. Maybe this helps in some way? |
You can reproduce with the following code: const eio = require('engine.io');
const eioc = require('engine.io-client');
const http = require('http');
const server = http.createServer();
const engineioServer1 = eio.attach(server);
const engineioServer2 = eio.attach(server);
server.listen(function () {
const socket = eioc(`ws://localhost:${server.address().port}`, {
transports: ['websocket']
});
}); or const eio = require('engine.io');
const eioc = require('engine.io-client');
const http = require('http');
const engineioServer = new eio.Server();
const server = http.createServer();
server.on('upgrade', function (request, socket, head) {
engineioServer.handleUpgrade(request, socket, head);
engineioServer.handleUpgrade(request, socket, head);
});
server.listen(function () {
const socket = eioc(`ws://localhost:${server.address().port}`, {
transports: ['websocket']
});
}); This is invalid usage of ws. There must be a 1 on 1 correspondence between a |
Try to monkey patch this line https://github.com/websockets/ws/blob/7.2.4/lib/websocket.js#L153 and change it like this: if (socket[kWebSocket]) {
throw new Error('Invalid usage');
} else {
socket[kWebSocket] = this;
} Your server process should crash with that error. |
It crashed with that error. I'll try to examine where the faulty code is. Most likely socket.io or socket-controller. |
Hi Dominic, did you get to the root of this already? Really scratching my head here... |
Had no luck yet. How do you use socket.io? I'm using it with socket-controller. |
I need to use transports: ['websocket'] as you do because Heroku is failing to provide session affinity between different server instances otherwise. |
I'm just using default socket.io-client and socket.io without any tooling |
I see. So it's not just me. @darrachequesne do you have an Idea where this originates? I had no luck so far.. |
@nxz91 Did you find a solution to your problem? |
Yes and no: I decided to start by scaling vertically using the |
@nxz91 Thanks for your response. I found the mistake. express-status-monitor spawned a second instance of socket.io and that caused the problems. BTW: We have also switched to Digitalocean, as it seems to be way cheaper than GCP or Heroku. I'm closing this issue now. |
Sounds like an interesting package, unfortunately I'm not using it so I
must be having another issue... :-(
…On Wed, 29 Apr 2020 at 19:59, Dominic ***@***.***> wrote:
@nxz91 <https://github.com/nxz91> Thanks for your response. I found the
mistake. express-status-monitor spawned a second instance of socket.io
and that caused the problems. BTW: We have also switched to Digitalocean,
as it seems to be way cheaper than GCP or Heroku. I'm closing this issue
now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#600 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADGA7Y2UCQ2A5PVBYQS7Y2TRPBTHFANCNFSM4MG25EHQ>
.
|
Closed due to inactivity, please reopen if needed. |
Note: for support questions, please use one of these channels: stackoverflow or slack
You want to:
Current behaviour
NodeJS Server crashes on tab refresh.
Steps to reproduce (if the current behaviour is a bug)
Use transports: ['websocket'] on your client. I'm using this library with socket-controller, which itself uses Socket-IO. But i'm quite sure, that the error tracks down to this library.
Expected behaviour
Should not crash.
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
Stacktrace
with this StackTrace.
error: uncaughtException: Cannot set property 'readyState' of undefined
TypeError: Cannot set property 'readyState' of undefined
at Socket.socketOnClose (backend/node_modules/ws/lib/websocket.js:838:24)
at Socket.emit (events.js:203:15)
at Socket.EventEmitter.emit (domain.js:448:20)
at TCP._handle.close (net.js:607:12) {"error":{},"stack":"TypeError: Cannot set property 'readyState' of undefined\n at Socket.socketOnClose (backend/node_modules/ws/lib/websocket.js:838:24)\n at Socket.emit (events.js:203:15)\n at Socket.EventEmitter.emit (domain.js:448:20)\n at TCP._handle.close (net.js:607:12)","exception":true,"date":"Mon Apr 13 2020 11:18:39 GMT+0200 (Central European Summer Time)","process":{"pid":48795,"uid":501,"gid":20,"cwd":"backend","execPath":"/usr/local/Cellar/node@10/10.18.1/bin/node","version":"v10.18.1","argv":["/usr/local/Cellar/node@10/10.18.1/bin/node","^backend/src/app.ts"],"memoryUsage":{"rss":146661376,"heapTotal":79376384,"heapUsed":63015720,"external":1091116}},"os":{"loadavg":[3.15966796875,3.02978515625,2.65869140625],"uptime":95890},"trace":[{"column":24,"file":"backend/node_modules/ws/lib/websocket.js","function":"Socket.socketOnClose","line":838,"method":"socketOnClose","native":false},{"column":15,"file":"events.js","function":"Socket.emit","line":203,"method":"emit","native":false},{"column":20,"file":"domain.js","function":"Socket.EventEmitter.emit","line":448,"method":"emit","native":false},{"column":12,"file":"net.js","function":"TCP._handle.close","line":607,"method":"close","native":false}]}
The text was updated successfully, but these errors were encountered: