Skip to content

Express Middleware Errors Do Not Stop Socket.IO Reconnections #5182

Open
@Nightmeru

Description

@Nightmeru

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions