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

[buggy silence] Mongoose should throw Error if model created on dumb (without config opts) connection #4979

Closed
nodkz opened this issue Feb 13, 2017 · 2 comments
Labels
backwards-breaking new feature This change adds new functionality, like a new method or class

Comments

@nodkz
Copy link
Contributor

nodkz commented Feb 13, 2017

In my app I'm switched from default connection to "manual" connections:

// main db file which creates several connections
const db1 = mongoose.createConnection(uri, opts);

// in model file
const User = db1.model('User', UserSchema);
User.find(...);

But in one file I forgot to change default mongoose connection on "manual" connection:

// main db file
// does not setup default connection any more 
// mongoose.connect(uri, opts);

// in model file
const Article = mongoose.model('Article', ArticleSchema);

And when try to make some request on Article, my app hang express requests (freeze them in pending status). How I understood it waiting when default connection will be initialized for proceeding operation. But connection will never be initialized.

@vkarpov15 it will be cool if you somehow add checking if a connection is not initialized and user performs some query operation on model with such dumb connection. I suppose operation (find, count, update ...) should throw an error (cb(err) or reject if promise).

PS. This case very hard to diagnose if using bunch of logic wrappers on top of mongoose. In my case express - react-relay-network-layer:batchExpressMiddleware - graphql-express - graphql-compose - graphql-compose-mongoose - mongoose.

PSS. For me, it's no error anymore, but further users may be blocked by this buggy silence.

@sobafuchs sobafuchs added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class and removed enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Feb 14, 2017
@vkarpov15 vkarpov15 added this to the 5.0 milestone Feb 15, 2017
@vkarpov15
Copy link
Collaborator

Yeah this is something we're planning on changing in 5.0. Buffering was really meant to minimize the number of callbacks necessary but that's much less of a problem now than it was in 2012. Not something we can really change right now without being backwards breaking though.

@vkarpov15
Copy link
Collaborator

I think we can close this one now that we have bufferTimeoutMS, which means that you'll at least get some error message after 10 seconds by default if you're using a model that is tied to a connection that you never called connect() on.

@vkarpov15 vkarpov15 removed this from the Parking Lot milestone Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-breaking new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

3 participants