"Segmentation fault (core dumped)" while testing with uWS.us_listen_socket_close (v16.5.0) #256
-
Hi again Alex, This error only happens on work deploy build machines (running Ubuntu Xenial), and not on my laptop (which runs mac os mojave), so it's difficult for me to debug it. Node version: 10.15.3 I think I've narrowed it down to this area in my tests: describe('message handler', () => {
const originalOpenHandler = sockets._openHandler;
beforeEach(() => {
sockets._opened = null;
});
afterEach(() => {
sockets._openHandler = originalOpenHandler;
sockets._opened = null;
if (sockets.listenSocket) {
uWS.us_listen_socket_close(sockets.listenSocket);
sockets.listenSocket = null;
sockets.listen(conf.websockets.port);
}
});
/* Open is considered complete once authentication has resolved. */
it('waits for open to complete', done => {
withSandbox(async sandbox => {
uWS.us_listen_socket_close(sockets.listenSocket);
const onMessageSpy = sandbox.spy(sockets, '_onMessage');
await new Promise(resolve => {
/*
We intentionally avoid making this an async function,
to mimic the current source code behavior.
*/
const wrappedOpenHandler = (ws, req) => {
setTimeout(() => {
sockets._openHandler(ws, req);
onMessageSpy.should.not.be.called();
resolve();
}, 500);
};
sockets._openHandler = wrappedOpenHandler;
sockets.listen(conf.websockets.port);
const ws = createClient({ token: tokenFor('frank') });
testMessageWithWs(ws, subscribeMessage);
});
done();
});
});
it('returns early if authentication fails', done => {
withSandbox(async sandbox => {
const error = Error('uh oh');
sandbox.stub(sockets, '_onConnection').callsFake(async () => {
await Promise.delay(100);
throw error;
});
sandbox.spy(sockets, '_onMessage');
const ws = createClient({ token: tokenFor('frank') });
testMessageWithWs(ws, subscribeMessage);
await Promise.delay(500);
sockets._onConnection.should.be.called();
sockets._onMessage.should.not.be.called();
done();
});
});
}); ^ This is a nested scope inside of a bigger integration test body; this.apiWsB = this._buildWebSocketBehavior();
this.apiWss = uWS
.App()
.ws('*', this.apiWsB)
.listen(port, token => {
if (token) {
this.listenSocket = token;
log.info(`Listening to port ${port}`);
} else {
log.error(`Failed to listen to port ${port}`);
}
}); ^ But in the test above, I am purposely closing the connection, and trying to reconnect before continuing testing. Please let me know if I can help clarify anything |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I can now replicate the issue in a docker container (the image is I'll keep this open for now as I debug, but I understand if this is outside of your area 👍 |
Beta Was this translation helpful? Give feedback.
-
uWS.us_listen_socket_close is a direct unchecked wrapper of us_listen_socket_close so any misuse leads to undefined behavior (it may crash, it may not crash, it may run buggy, etc). You have to be very careful with that function |
Beta Was this translation helpful? Give feedback.
-
Thanks! This seems to be an issue with the way my tests are configured so I'll be closing this. Happy New Year! |
Beta Was this translation helpful? Give feedback.
uWS.us_listen_socket_close is a direct unchecked wrapper of us_listen_socket_close so any misuse leads to undefined behavior (it may crash, it may not crash, it may run buggy, etc).
You have to be very careful with that function