socketio / socketio/socket.io

Errors when using uWebsockets while clients are connected and server restarts

Open
#5,330 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

to triage
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

Describe the bug
Hi,

at my company we are in the middle of switching from express to uWebSockets.

We use

  • Nestjs
  • Ultimate-Express
  • socket.io with attachApp
  • engine.use(sessionMiddleware) <- thats the problem... or maybe not? (express-session)

While everything works really good, there is one thing we get errors.

  1. Server starts deployment, after that clients can connect and everything works
  2. Server goes down, restarts, etc. the client browser stays open!!
  3. When Server is up again, the reconnecting begins (sessionMiddleware is called)
  4. Various errors are showing up:

Image

  1. Ok so I first thought hmm my sessionMiddleware does some bad things
  2. But after some debugging, I could fix it quite easy in uServer -> handleUpgrade

Image

  1. I had to cork the response write and upgrade
  2. I saved the header before entering the async callback

I'm sry that I cannot really give a code example for this problem.

But does this seems to be a bug or just a problem in my project?

Nice to know, I absolutely don't have any error or problems after changing these few lines.

(Re-)Connecting with engine.use and express-session middleware works like a charm.

Platform:

  • OS: [e.g. Linux, Windows, Mac]

Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the uServer handleUpgrade path and the engine.use(sessionMiddleware) integration described in the report. Reproduce a server restart while browser clients remain connected, then trace reconnect handling and response writes; done means the reported errors no longer occur with this setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, nodejs, typescript
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.