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

fix(web-server): ignore future socket errors #3402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mgroenhoff
Copy link

Karma sometimes reports uncaught exceptions (ECONNRESET) which causes it to exit the process with a non-zero exit code.

Fixes #3295

Karma sometimes reports uncaught exceptions (ECONNRESET) which causes it to exit the process with a non-zero exit code.

Fixes karma-runner#3295
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@karmarunnerbot
Copy link
Member

Build karma 62 completed (commit 6b00be646c by @mgroenhoff)

@AppVeyorBot
Copy link

Build karma 2460 completed (commit 6b00be646c by @mgroenhoff)

@mgroenhoff
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@karmarunnerbot
Copy link
Member

Build karma 61 completed (commit 6b00be646c by @mgroenhoff)

@@ -93,6 +93,8 @@ function createWebServer (injector, config) {

server.on('upgrade', function (req, socket, head) {
log.debug(`upgrade ${req.url}`)
// ignore future socket errors
socket.on('error', () => {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this will cause all errors to be ignored after we start the two-way socket-io.

The spurious errors from #3295 only occur after the run completes. Isn't the time to turn off errors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that you don't want those socket errors to crash the entire Karma process and this prevents just that. It still allows for the upgrade handler(s) to attach their own error event handlers.

Maybe I should change the comment so it says exactly that: that it only prevents the process from crashing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact. I think this is somewhat similar to what Node.js does when it's HTTP server receives a new connection. It attaches an error handler to prevent it from going down. It forwards it to the 'clientError' event on the server, which when emitted does not crash if it does not have any handlers. But in the case if an upgrade request it totally lets go of the socket and removes that error handler so the socket is entirely yours.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed your reply.

Yes, just change the comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spurious errors from #3295 only occur after the run completes. Isn't the time to turn off errors?

I agree. While this fixes the problem it will swallow errors in other situations. At the bare minimum, it should log an error as a warning similar to https://github.com/karma-runner/karma/blob/master/lib/server.js#L145. Ideally, it should also reset the handler after the complete event is received to target specifically #3295, where we don't care about the browser errors anymore.

@johnjbarton johnjbarton reopened this Nov 26, 2020
@AppVeyorBot
Copy link

Build karma 2783 completed (commit 8f39f90852 by @mgroenhoff)

@karmarunnerbot
Copy link
Member

Build karma 386 completed (commit 8f39f90852 by @mgroenhoff)

@karmarunnerbot
Copy link
Member

Build karma 385 completed (commit 8f39f90852 by @mgroenhoff)

@costescuandrei
Copy link

Any update on this? Is anyone who knows the code willing to do the required review?

@johnjbarton
Copy link
Contributor

I reviewed but never received updates.

@jginsburgn
Copy link
Member

jginsburgn commented May 12, 2021

@mgroenhoff do we still need to merge this PR?

@jginsburgn jginsburgn force-pushed the master branch 12 times, most recently from fe000ad to b9831cc Compare October 20, 2021 03:37
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

Successfully merging this pull request may close these issues.

Karma sometimes generates Error: read ECONNRESET after successful test run
9 participants