-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #1564
Comments
@lpinca i found that as a server: |
https://careeron.ecspool.com |
I can't see how this can happen:
Please create a minimal test case, using only |
i found that for one same websocket,the socketOnClose function is called twice:for the first,you have make "this[kWebSocket]=undefined",and so the seconed,this[kWebSocket] is undefined |
If the Also the listener removes itself after it is called. See https://github.com/websockets/ws/blob/6.2.1/lib/websocket.js#L823 |
but how can i resolve this problem? |
I don't know. Show me where the bug is in |
but what ever,the Websocket should not be crashed
发自我的iPhone
…------------------ Original ------------------
From: Luigi Pinca <notifications@github.com>
Date: Sun,May 12,2019 10:44 PM
To: websockets/ws <ws@noreply.github.com>
Cc: mccoysc <364589886@qq.com>, Author <author@noreply.github.com>
Subject: Re: [websockets/ws] Cannot set property 'readyState' of undefined (#1564)
I don't know. Show me where the bug is in ws and how to reproduce it then maybe I can help. I have no clue what your code is doing.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I cannot make it crash and that's why I'm asking you to write a test case to reproduce the issue. This is what I tried with the info you gave me and it works as expected, no exception is thrown. const WebSocket = require('.');
const { createServer } = require('https');
const { readFileSync } = require('fs');
const server = createServer({
cert: readFileSync('test/fixtures/certificate.pem'),
key: readFileSync('test/fixtures/key.pem')
});
const wss = new WebSocket.Server({ server });
wss.on('connection', function(ws, { url }) {
const params = new URLSearchParams(url.slice(url.indexOf('?')));
ws.on('close', function() {
console.log('closed connection %s', params.get('id'));
});
});
server.listen(8080, function() {
const options = { rejectUnauthorized: false };
const ws1 = new WebSocket('wss://localhost:8080/?id=1', options);
const ws2 = new WebSocket('wss://localhost:8080/?id=2', options);
ws1.on('open', function() {
ws1.close();
});
ws2.on('open', function() {
ws2.close();
});
}); |
you can run: and browse at |
It does not crash on my machine. |
you browser url https://127.0.0.1 and then you refresh one tab |
yes, also this is not a good test case. It's a whole app can't even see where
|
in "node_modules/gun/lib/ws.js" |
I don't have time to debug other people code, sorry. I have no clue what Btw I tried again and it does not crash on my machine. I've opened 3 tabs and refreshed all of them. |
What Node.js version are you using? What OS? |
Nodejs v11.9 and v10.11.0
Os:win10 and centOS 6.8
…------------------ Original ------------------
From: Luigi Pinca <notifications@github.com>
Date: Mon,May 13,2019 1:13 AM
To: websockets/ws <ws@noreply.github.com>
Cc: mccoysc <364589886@qq.com>, Author <author@noreply.github.com>
Subject: Re: [websockets/ws] Cannot set property 'readyState' of undefined (#1564)
What Node.js version are you using? What OS?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Closing as I can't reproduce it. |
may be emit 'close' multi times. |
We hit a similar exception when 'error' event is received after 'close'. It happens if I have an open websocket, and I'm profiling with Chrome. When I click "Stop recording heap profile", it pauses the application for a few seconds, and this leads to a crash (sometimes). I don't have a minimal example that reproduces it yet, but I'll try to reproduce later today. Trace:
|
Thank you. That was it. |
I introduced the same problem and found out that other libraries somehow breaks the connection on express server. On my case it was 'express-status-monitor'. |
I ran into the same problem yesterday when I played with the Hackathon Starter. The "express-status-monitor" breaks the connection, indeed. |
No, because if we do it we mask a bug instead of fixing it. The websocket cannot be undefined in that handler. If it is there is bug. |
Maybe I'm misunderstanding but it is literally this method that sets the websocket to undefined, if it's already been called it should do nothing. There is no way to handle this error gracefully from the outside and the cause of it is in another library. How do you propose someone deals with this, as in our case it is recycling a live service whenever it happens? |
That error must not be handled gracefully. It should crash the process. We can put an
Fix the problem that is causing it. Fix the invalid usage of |
Read my comments here #1787, they should help you. |
For me the error was thrown because I failed to remove the // setup
this.wsServer = new ws.Server({
noServer: true
})
// upgrade cbk init
this.upgradeCbk = (request, socket, head) => {
const pathname = url.parse(request.url).pathname;
if (pathname === this.path) {
this.wsServer.handleUpgrade(request, socket, head, ws => {
this.wsServer.emit('connection', ws, request);
});
}
}
this.server.on('upgrade', this.upgradeCbk); // later on when shutting down ws server
this.wsServer.close()
this.server.removeListener("upgrade", this.upgradeCbk) |
websocket.readyState = WebSocket.CLOSING;
^
TypeError: Cannot set property 'readyState' of undefined
at TLSSocket.socketOnClose (/node_modules/ws/lib/websocket.js:826:24)
at TLSSocket.emit (events.js:187:15)
at _handle.close (net.js:606:12)
at Socket.done (_tls_wrap.js:386:7)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at TCP._handle.close (net.js:606:12)
The text was updated successfully, but these errors were encountered: