Skip to content

Executing a Broken Statement Causes a Hang  #54

@linden

Description

@linden

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions