Skip to content

autoRemove native causing error on close #413

Closed
@lmeerma

Description

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.

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions