question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught exception in reader crashing application

See original GitHub issue

Hi!

I have an issue where if the nsqd process goes down or the network has some problem, it will unconditionally crash my application if I have an open Reader at the time this happens.

What happens is that I’m listening to a certain topic and channel and as part of this process the reader will try to write some data over the NSQDConnection. The write method on nsqdconnection.js:424 will defer the actual writing by deferring the _flush function. When the flush function is executed the connection is down so the this.conn.write() call on nsqdconnection.js:434 throws ERR_STREAM_WRITE_AFTER_END. However, this is running a deferred context on the main event loop and cannot be caught, so it bubbles all the way up and kills my application.

Expected behaviour: Handle the error and trigger the ‘error’ event on the Reader instance.

Actual behaviour: Exception bubbles through the stack and kills the application. Impossible to trace which Reader that caused the error and therefore difficult to try to recover.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jheandercommented, Feb 28, 2020

@nekufa Your use-case is almost identical to ours and we structured our first solution in the same way and had approximately the same frequency of failures. The strange thing isn’t really that the connection is closed, since that can happen due to clients dropping out, but that the exception is not caught and instead allowed to bubble all the way to the top and kill the application.

And even if we managed to catch it on application level, the context would be lost and we were unable to determine which connection that caused the problem and should be retried.

1reaction
jheandercommented, Feb 28, 2020

@nekufa We changed our application logic to only use a single long-lived Reader instance and filtering and distributing the messages in application logic. Since then we have not seen this error in production. I am pretty confident though that there is a bug or race condition here somewhere since when we had a short Reader life cycle this crash happened a couple of times per day and I mostly think that now the Reader turnover is so low that combined with the low frequency of this error it might take months or years before it happens again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My Application crashes if there is an unhandled exception in ...
At first the golden rule is: If your code creates an exception, it has to be handled otherwise your application runs in a...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
If an uncaughtException happens, the recommendation is to always crash your process, let it crash.
Read more >
Uncaught Exceptions in Node.js - George Ornbo
You should let your application crash, find uncaught exceptions and fix them. This is clearly insane. You should swallow errors silently.
Read more >
AutoCAD crashes or freezes when saving, closing, or plotting ...
Issue: When trying to save, close, plot, or publish a drawing in AutoCAD, or exiting the program right after doing one of these...
Read more >
IIS Crashing unexpectedly in the .Net Framework - Geekflare
To fix this permanently, a developer must handle all exceptions in the application. As a workaround, you can change unhandled exception policy back...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found