Change stream: Mongoose suppresses error event after initial close #14177
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.5.3
Node.js version
20.5.1
MongoDB server version
6.0
Typescript version (if applicable)
No response
Description
In Mongoose, a change in the error event handling for MongoDB change streams appears to have inadvertently affected the ability to catch errors after the connection has been closed. Specifically, the commit 386c366 introduced a change where the error event is suppressed after the change stream has been initially closed. This suppression prevents the propagation of errors that the MongoDB driver throws during reconnection attempts, as outlined in the MongoDB documentation for Change Streams.
The workaround is to subscribe directly on the driverChangeStream:
Steps to Reproduce
Expected Behavior
The expected behavior is that Mongoose should emit error events from the MongoDB change stream even after the stream has been closed. This would enable applications to catch and handle these errors, especially to implement custom reconnection logic in scenarios where maintaining an active change stream is critical.
The text was updated successfully, but these errors were encountered: