Skip to content
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

Error with uWebSockets.js: uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback #5066

Open
eighthlucky opened this issue Jun 26, 2024 · 0 comments
Labels
bug Something isn't working package:engine.io This concerns the "engine.io" package

Comments

@eighthlucky
Copy link

eighthlucky commented Jun 26, 2024

Describe the bug
When running socket.io and uNetworking/uWebSockets.js, we sometimes get this error:

Error: uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback, or after a successful response. See documentation for uWS.HttpResponse and consult the user manual.

It happens rarely (~10 times in last 30 days). We've recently come up with a way to replicate it locally, although I'm not sure if it's the same cause as on production.

To Reproduce

Engine.IO server version: 6.6.0
Engine.IO client version: 6.5.4

import { Server } from 'socket.io';
import { connect } from 'socket.io-client';
import { App as createApp } from 'uWebSockets.js';

const PORT = 3000;
const SERVER_URL = `http://localhost:${PORT}`;

// Initialize socket.io server with uWebSockets app
const server = new Server({ serveClient: false });
const app = createApp();
server.attachApp(app);

// Listen and wait for it to be ready
await new Promise((r) => app.listen(PORT, r));

// Create a new socket.io client and wait for it to connect
const socket = connect(SERVER_URL);
await new Promise((r) => socket.once('connect', r));

// Mimic a new socket.io client connection with an already connected session ID
// Engine.io will close the connection, but will incorrectly attempt to upgrade it afterwards
// See https://github.com/socketio/engine.io/blob/6.6.0/lib/userver.ts#L213
try {
  new WebSocket(
    `ws://localhost:3000/socket.io/?EIO=4&transport=websocket&sid=${socket.io.engine.id}`,
  );
} catch {}

// Exit when there is no error
setTimeout(() => process.exit(0), 2_000);

Note: The above snippet will require Node 22 to run.

Expected behavior
I expect it to exit normally after the 2s timeout.

Actual behavior
It crashes with the error message mentioned above.

Platform:

  • Device: MacBook Pro 2019
  • OS: Ventura
  • Node versions: 20.13.1, 20.15.0, 22.3.0

Additional context

@eighthlucky eighthlucky added the bug Something isn't working label Jun 26, 2024
@darrachequesne darrachequesne transferred this issue from socketio/engine.io Jul 9, 2024
@darrachequesne darrachequesne added the package:engine.io This concerns the "engine.io" package label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:engine.io This concerns the "engine.io" package
Projects
None yet
Development

No branches or pull requests

2 participants