Skip to content

"Stream not found" error in a long running write transaction #135

@ganigeorgiev

Description

@ganigeorgiev

I'm not sure if this is an intended limitation but if a write transaction takes longer to complete, the connection/stream seems to get terminated abruptly as if there is some timeout.

Here is minimal Go example:

package main

import (
	"context"
	"database/sql"
	"log"
	"time"

	_ "github.com/tursodatabase/libsql-client-go/libsql"
)

func main() {
	url := "..."

	db, err := sql.Open("libsql", url)
	if err != nil {
		log.Fatalf("failed to open db %s: %s", url, err)
	}
	defer db.Close()

	tx, err := db.BeginTx(context.Background(), nil)
	if err != nil {
		log.Fatalf("BeginTx error: %v", err)
	}
	defer tx.Rollback()

	_, err = tx.Exec("CREATE TABLE IF NOT EXISTS `test` (id VARCHAR(255) PRIMARY KEY NOT NULL)")
	if err != nil {
		log.Fatalf("before sleep error: %v", err)
	}

	// simulate large and slow transaction
	time.Sleep(10 * time.Second)

	_, err = tx.Exec("CREATE TABLE IF NOT EXISTS `test` (id VARCHAR(255) PRIMARY KEY NOT NULL)")
	if err != nil {
		log.Fatalf("after sleep error: %v", err)
	}

	err = tx.Commit()
	if err != nil {
		log.Fatalf("commit error: %v", err)
	}
}

The above fails with the following error:

2025/04/20 16:01:21 after sleep error: failed to execute SQL:
error code 404: stream not found: 0fadcb26:01965349-eea6-79f0-8f02-80077f780223

For more context, the issue was original reported in pocketbase/pocketbase#6746.

It is also possible to be related to tursodatabase/libsql#985.

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