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

MongoNetworkTimeoutError crashes nodejs process #14377

Closed
2 tasks done
LvChengbin opened this issue Feb 26, 2024 · 4 comments · Fixed by #14390
Closed
2 tasks done

MongoNetworkTimeoutError crashes nodejs process #14377

LvChengbin opened this issue Feb 26, 2024 · 4 comments · Fixed by #14390
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@LvChengbin
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.2.0

Node.js version

19.4.0

MongoDB server version

6.2.0

Typescript version (if applicable)

5.2.2

Description

MongoNetworkTimeoutError crashes my process even though I catch the error with connection.on( 'error', () => {} ).
The error event is triggered while the server isn't reachable, but the process is crashed.

Steps to Reproduce

const connection = mongoose.createConnection( uri, options );
connection.on( 'error', e => { console.log( e ) } );

Expected Behavior

No response

@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Feb 26, 2024
@IslandRhythms
Copy link
Collaborator

Need more details. What's your connection string look like. What else are you doing?

@LvChengbin
Copy link
Author

I want to say that when there's a connection error, The error should be catchable instead of crashing the process, without asking why the connection timed out.

@vkarpov15
Copy link
Collaborator

t looks like the following script throws an uncaught error, we're investigating

'use strict';

const mongoose = require('mongoose');

const conn = mongoose.createConnection('mongodb://fail:27017/mongoose_test', { serverSelectionTimeoutMS: 1000 });
conn.on('error', err => console.log('Error hander', err));

@vkarpov15
Copy link
Collaborator

In general, we would recommend handling errors using asPromise(), like const conn = await mongoose.createConnection(uri).asPromise() rather than relying on on('error'), but we'll fix this issue.

@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Feb 27, 2024
@vkarpov15 vkarpov15 added this to the 8.2.1 milestone Feb 27, 2024
vkarpov15 added a commit that referenced this issue Feb 28, 2024
vkarpov15 added a commit that referenced this issue Mar 1, 2024
fix(connection): avoid unhandled error on createConnection() if on('error') handler registered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
3 participants