sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

Executing a Broken Statement Causes a Hang

Open linden opened this issue 1 year ago • 1 comments

Hi,

whenever you try to execute an invalid statement in a transaction an error isn't returned (nor a panic thrown) the program just hangs.

I'd initially noticed this when inserting twice into a table that expected a column to be unique assuming I'd see an error but instead the program just hung.

this does not seem to be directly related to the unique constraint, it seems to happened with any invalid statement; even if they aren't valid SQL.

here's a example:

package main

import (
	"context"
	"log"

	"github.com/tailscale/sqlite/sqliteh"
	"github.com/tailscale/sqlite/sqlitepool"
)

var db *sqlitepool.Pool

func init() {
	var err error

	db, err = sqlitepool.NewPool("file:./db.sqlite", 10, func(init sqliteh.DB) error { return nil }, nil)

	if err != nil {
		panic(err)
	}
}

func main() {
	defer db.Close()

	transaction, err := db.BeginTx(context.Background(), "")

	if err != nil {
		panic(err)
	}

	log.Println("executing invalid statement")

	err = transaction.Exec("this should throw an error")

	if err != nil {
		panic(err)
	}

	log.Println("done")

	err = transaction.Commit()

	if err != nil {
		panic(err)
	}
}

running this program yields the following then hangs forever:

% go run main.go
2023/03/01 22:43:26 executing invalid statement

linden avatar Mar 02 '23 06:03 linden