Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

If opening a database fails, promises returned by open and deferred operations are not rejected #710

@abacabadabacaba

Description

@abacabadabacaba

With levelup, it is possible to use database objects before they are fully open. If a method that needs an open database is called, the call is deferred until the open operation is complete. Also, if the open method is called while the database is being opened, it will wait for the running open operation to complete instead of initiating a new one.

If the open operation fails, a user would expect all the deferred operations to fail as well. However, this is not what happens. Instead, error event is fired (which is not fired for any other errors), and the deferred calls never finish: callbacks are never called, promises are never settled.

I think that if open operation fails, database should enter an error state in which all pending and future calls immediately fail with an error. While in the current code it is possible to attempt to reopen a database after an error, this is rarely what the user wants. In the current code, if a method is called after a failed attempt to open the database, it will be deferred in anticipation that the user will try to open the database again. In asynchronous code, it is easy to call a method after the open operation fails but before the failure is processed by the user code. In this case, if the user code doesn't attempt to reopen the database, these calls will hang.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions