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

Can´t catch/suppress ERR_CONNECTION_REFUSED #1178

Closed
profezzional opened this issue Dec 15, 2017 · 2 comments
Closed

Can´t catch/suppress ERR_CONNECTION_REFUSED #1178

profezzional opened this issue Dec 15, 2017 · 2 comments

Comments

@profezzional
Copy link

profezzional commented Dec 15, 2017

You want to:

[x] report a bug
[ ] request a feature

Current behaviour

I know this is a pretty much a dupe of #1023, but that issue wasn't really solved and now seems dead.

I've googled a bit, but this solution(-ish) from @w0xz doesn't really apply to me, since I'm running an Angular 5 app and the socket initialization is happening in components.

Additionally, #881 claimed to have solved #485, but I guess that PR didn't get merged?
I understand that it's an exception thrown by Chrome itself, and it may also be an engine.io or zone.js issue, but I figure this is the best place to start.

My issue is that I'm getting this exception thrown in the Chrome console when my Angular 5 app is running and my local nodeJS server isn't:

GET http://localhost:7070/socket.io/?EIO=3&transport=polling&t=M1NX3_U
net::ERR_CONNECTION_REFUSED

The socket.io events are being emitted properly when I log them like so:

this.socket = SocketIO(this.socketURL, this.socketOptions);
this.socket.on('connect_error', (error) => {
    console.log('connection_error', error); // this is getting logged, like it's supposed to
    // ^ same for all the other events from the socket
});
this.socket.io.on('connect_error', (error) => {
    console.log('connection_error', error); // this is also getting logged, like it's supposed to
    // ^ same for all the other events from the socket manager
});

However, the exception is getting thrown in the console anyway, even when I have handlers for all the events listed in the docs, both from the socket and the socket manager.

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

Run an app using socket.io-client and a server using socket.io, then stop the server (or run only the app).

Expected behaviour

My impression is that handling the socket and socket.io events should prevent a connection-refused error from being thrown and/or logged.

It's a nuisance during clientside development when I don't have my local server running, even if I catch and don't log the socket.io events, the exception fills up my Chrome console with a sea of red, and I'd rather not turn off autoReconnect every time I switch between local and live environments.

Setup

  • Windows 10
  • Chrome 65
  • socket.io-client v2.0.4
  • zone.js v0.8.20
  • angular v5.1.3

Other information (e.g. stacktraces, related issues, suggestions how to fix)

I traced down into the engine.io and zone.js calls, and it's getting thrown somewhere when the XMLHttpRequest is getting sent during XHR polling, when the send call is applied in zone's task scheduling. For some reason any changes to the XMLHttpRequest file aren't getting applied (I suspect an angular-cli issue since it's in node_modules, but other changes are working, so I don't know), so I couldn't log anything from the send call or try to catch the exception at the level where it's probably actually being thrown.

Stacktrace (the line numbers have probably since changed, but the second half is the important part anyway) from right before the request.send() call gets applied in zone (when the exception gets thrown):

    at ZoneTask.scheduleTask [as scheduleFn] (webpack-internal:///../../../../zone.js/dist/zone.js:2933:25)
    at ZoneDelegate.scheduleTask (webpack-internal:///../../../../zone.js/dist/zone.js:411:32)
    at Object.onScheduleTask (webpack-internal:///../../../../zone.js/dist/zone.js:301:35)
    at ZoneDelegate.scheduleTask (webpack-internal:///../../../../zone.js/dist/zone.js:405:51)
    at Zone.scheduleTask (webpack-internal:///../../../../zone.js/dist/zone.js:236:43)
    at Zone.scheduleMacroTask (webpack-internal:///../../../../zone.js/dist/zone.js:259:25)
    at eval (webpack-internal:///../../../../zone.js/dist/zone.js:2966:35)
    at XMLHttpRequest.proto.(anonymous function) [as send] (webpack-internal:///../../../../zone.js/dist/zone.js:1366:30)
    at Request.create (webpack-internal:///../../../../engine.io-client/lib/transports/polling-xhr.js:263:9)
    at new Request (webpack-internal:///../../../../engine.io-client/lib/transports/polling-xhr.js:164:40)
    at XHR.request (polling-xhr.js:92)
    at XHR.doPoll (polling-xhr.js:122)
    at XHR.Polling.poll (polling.js:118)
    at XHR.Polling.doOpen (polling.js:63)
    at XHR.Transport.open (transport.js:80)
    at Socket.open (socket.js:245)
    at new Socket (socket.js:119)
    at Socket (socket.js:28)
    at Manager.open.Manager.connect (manager.js:226)
    at eval (manager.js:540)
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.js:4747)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at ZoneTask.invokeTask (zone.js:499)
    at ZoneTask.invoke (zone.js:488)
    at timer (zone.js:2040)

[it wouldn't log anything before timer]

chandrajob365 added a commit to chandrajob365/traceroute-visualizer that referenced this issue Jan 1, 2018
net::ERR_CONNECTION_REFUSED - Cann't be handled due to opend bug in Socket.io

Issue - socketio/socket.io-client#1178
@kg
Copy link

kg commented Mar 27, 2018

Chrome showing errors in the console on failed WS connections is a chrome bug, fyi. It happens if you use websockets directly regardless of whether you set an error handler. So if you want it fixed it's worth filing a bug over on the chromium bug tracker.

@darrachequesne
Copy link
Member

For future readers: ERR_CONNECTION_REFUSED errors are emitted by the browser itself, and there is unfortunately nothing that we can do to silence them.

Added in the documentation here: https://socket.io/docs/v3/logging-and-debugging/#Error-logs-in-the-browser-console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants