Express Middleware Errors Do Not Stop Socket.IO Reconnections
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63.2k
- Forks
- 10.3k
- Avg merge
- 11d 20h
- Merged PRs (30d)
- 2
Description
Describe the bug
The documentation states that middleware errors should stop the client from reconnecting. However, this does not seem to be the case for middleware created using io.engine.use.
To Reproduce
Socket.IO server version: 4.7.5
Socket.IO client version: 4.7.5
Server
For example, let's create two middlewares that will trigger errors:
First:
io.use((socket, next) => {
next(new Error('thou shall not pass and stop'))
})
Second:
io.engine.use((req, res, next) => {
next(new Error('thou shall not pass'))
})
Client
Log the response as follows:
socket.on('connect_error', (err) => {
console.log('websocket error:', err.message, socket.active)
})
Using the first middleware, the response is:
websocket error: thou shall not pass and stop false
Using the second middleware, however, the response is:
websocket error: xhr poll error true
websocket error: xhr poll error true
websocket error: xhr poll error true
...
Expected behavior
I'm not sure if I missed something, but I believe that this type of middleware should, in fact, stop reconnections!
Platform:
- Device: PC
- OS: Windows 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported server and client snippets using io.use, io.engine.use, and connect_error, reproducing the behavior with Socket.IO 4.7.5. Trace how each middleware error is handled during Engine.IO polling and add a regression test showing that the engine middleware error stops reconnections, matching the existing io.use behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100