Skip to content

Pool.Close leaves behind WAL files #119

Open
@acrispino

Description

@acrispino

Using version 23d646f

With the program below, the function that uses Pool leaves behind WAL files after the pool is closed. It is almost as if the Conn is not getting closed, but that doesn't make sense, because Pool definitely closes its Conns.

package main

import (
	"fmt"
	"os"

	"crawshaw.io/sqlite"
	"crawshaw.io/sqlite/sqlitex"
)

const dbSchema = `
CREATE TABLE IF NOT EXISTS foobars (id INTEGER PRIMARY KEY AUTOINCREMENT);
INSERT INTO foobars values (NULL);
`

func main() {
	err := initDBWithPool("pool.db")
	if err != nil {
		fmt.Fprintf(os.Stderr, "pool: %v\n", err)
		os.Exit(1)
	}
	err = initDBWithConn("conn.db")
	if err != nil {
		fmt.Fprintf(os.Stderr, "conn: %v\n", err)
		os.Exit(1)
	}
}

func initDBWithConn(path string) (err error) {
	conn, err := sqlite.OpenConn(path, sqlite.OpenFlagsDefault)
	if err != nil {
		return err
	}
	defer func() {
		closeErr := conn.Close()
		if err == nil {
			err = closeErr
		}
	}()
	return sqlitex.ExecScript(conn, dbSchema)
}

func initDBWithPool(path string) (err error) {
	pool, err := sqlitex.Open(path, sqlite.OpenFlagsDefault, 1)
	if err != nil {
		return err
	}
	defer func() {
		closeErr := pool.Close()
		if err == nil {
			err = closeErr
		}
	}()
	conn := pool.Get(nil)
	defer pool.Put(conn)
	return sqlitex.ExecScript(conn, dbSchema)
}
$ ls -1
conn.db
pool.db
pool.db-shm
pool.db-wal

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions