socketio / socketio/socket.io

Websocket connection error cannot be caught by event handler

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

Nobody has claimed this yet.

package:engine.io
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

You want to:
  • report a bug
  • request a feature
Problem Description

Connection fails silently, causing headaches and hours of time spent debugging.

I had a problem in my webpack build, causing connection to fail silently on Node, caused by this websocket issue (which in turn is caused by webpack's broken default build settings).

To be clear: This bug is not caused by engine.io, but it is accidentally silencing it.

Specifically, the problem is in websocket.doOpen's try/catch handler. It will emit the error, but since, the first time around, doOpen is called from the Manager.constructor, it would be impossible to register any event handler at that point, making this error always go unnoticed, no matter what you do.

Here is the callstack:

image

Steps to reproduce (if the current behaviour is a bug)

Anything that causes websocket.doOpen to fail (such as a default webpack build run on Node) will fail silently.

Discussion

Maybe there should be a default error handler that acts if none was registered? This would alsomake it easier for people to get started and reliably find any potential problem without having to debug the dependency?

As an alternative, I am also thinking, straight up throwing the error when it happens in the constructor (or in general, if no error handler is provided) would still be better than what it is right now?

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 with lib/transports/websocket.js at websocket.doOpen and trace its first call from Manager.constructor. Reproduce a failure that reaches the try/catch, then determine how the error should be exposed when no handler can be registered; done means the failure is no longer silent and the behavior is covered by the relevant client tests, though no test file is named here.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.