Skip to content

Close properly Sqlite connections #6798

Closed

Description

@francescoinfante

What you are doing?

Using Sequelize with Sqlite.

What do you expect to happen?

I want the connection with Sqlite to be closed properly and the file *shm and *wal deleted.

What is actually happening?

*shm and *wal files persist after termination of the process.

__Dialect: sqlite
__Database version: 3.1.6
__Sequelize version: 3.24

A PR would be accepted? I would implement disconnect() in the sqlite connection manager. disconnect() would call close() on all this.connections

Activity

  1. felixfbecker commented on Nov 3, 2016

    @felixfbecker
    Contributor

    Doesn't sequelize.close() work for you?

  2. francescoinfante commented on Nov 4, 2016

    @francescoinfante
    ContributorAuthor

    No, sequelize.close() with sqlite does nothing.
    sequelize.close() calls this.connectionManager.close()
    this.connectionManager.close() calls this.onProcessExit()
    this.onProcessExit() will do something only if this.pool is defined. But it's undefined for sqlite.

  3. added
    type: bug
    good first issue
    dialect: sqlite
    on Nov 14, 2016
  4. nadrane commented on Dec 26, 2016

    @nadrane
    Contributor

    I can fix this one. As @francescoinfante said, we're not closing the connection because the current implementation of onProcessExit assumes that we are using pools:

      onProcessExit() {
        if (this.pool) {
          this.pool.drain(() => {
            debug('connection drain due to process exit');
            this.pool.destroyAllNow();
          });
        }
      }
    

    As it stands today, the SqliteDialect class does not even make an attempt to use pools. I noticed #5914 makes it forbidden to not use pools. This PR doesn't mention how sqlite still does not have pooling support. And that's where I'm at a crossroads. I'm guessing it was an explicit decision not to support pooling for sqlite since the database isn't really designed for concurrent connections (is this an inaccurate statement? This suggests we can have concurrent connections)).

    So is the solution to this issue to support pooling for sqlite anyway (maybe just limiting the number of connections to 1), giving us a common API for managing all SQL dialects? Or is it to add an exception in onProcessExit to handle sqlite a little bit differently? Or is it to support pooling with an unthrottled number of connections like every other DB?

  5. Deilan commented on Sep 5, 2017

    @Deilan

    Not stale.

  6. aguynamedben commented on Apr 16, 2019

    @aguynamedben

    Does anybody know if this bug could have caused a SQLITE_CORRUPT error? I.e. if a process was force quit during a database write or if the process was quit in the middle of a write?

    We're on [email protected] (before this fix was merged), SQLCipher, and Electron and have a few users that have gotten SQLITE_CORRUPT. I'm wondering if their app was force quit somehow and the database connection wasn't closed properly, leaving the on-disk SQLite database in a corrupt state.

    UPDATE: I don't think we're using WAL mode... unless Sequelize is doing that for us?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: sqlitegood first issuetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions