tailscale / tailscale/sqlite

Executing a Broken Statement Causes a Hang

Open
#54 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
225
Forks
11
Avg merge
20m
Merged PRs (30d)
2

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided main.go reproduction and trace the sqlitepool.NewPool, BeginTx, and transaction.Exec entry points. Determine why an invalid statement in a transaction does not return and verify the fix by confirming the example reports an error instead of hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sqlite
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.