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

autoRemove native causing error on close #413

Closed
lmeerma opened this issue Mar 26, 2021 · 4 comments
Closed

autoRemove native causing error on close #413

lmeerma opened this issue Mar 26, 2021 · 4 comments

Comments

@lmeerma
Copy link

lmeerma commented Mar 26, 2021

When having the autoRemove function set to native, connect-mongo starts creating an index.

collection.createIndex({ expires: 1 }, { expireAfterSeconds: 0, ...this.options.writeOperationOptions });

Since this method is asynchroneous and it is not waited for its completion, the following error is thrown when the close() method is called immediately afterwards because the index creation is still running in the background.

(node:27307) UnhandledPromiseRejectionWarning: MongoError: Cannot use a session that has ended

Calling close() immediately after creating the session store is a valid behaviour when somewhere in the following startup process of the server a critical error occurs and the server should shutdown gracefully. This currently doesn't work due to the error. The same behaviour probably applies when autoRemove is set to interval because there the deleteMany() method is called without waiting for its completion.

Either making the whole creation process asynchroneous or emitting an event once the various asynchroneous calls have finished would solve the problem.

@mingchuno
Copy link
Collaborator

@lmeerma For your use case, maybe you can disable the index creation and manage it by yourself?

@lmeerma
Copy link
Author

lmeerma commented Mar 27, 2021

That would be possible. But I think this either needs a fix or a warning in the README. This problem is not trivial and took me some time to understand where this bug is coming from. Calling two valid methods of an SDK shouldn't result in an error. So I think this needs at least a warning.

What do you think?

@mingchuno
Copy link
Collaborator

mingchuno commented Mar 27, 2021

I think adding a warning is good 👍🏻 Will add it and refer to this issue later.

@mingchuno
Copy link
Collaborator

added in 94b65f6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants