Skip to content

RunTransaction hangs if the provided function panics #386

@will-arxed

Description

@will-arxed

Reproduction:

package main

import (
	"context"
	"database/sql"
	"fmt"
	"os"

	spannerdriver "github.com/googleapis/go-sql-spanner"
)

func main() {
	ctx := context.Background()

	db, err := sql.Open("spanner", fmt.Sprintf("projects/%s/instances/%s/databases/%s", os.Getenv("PROJECT"), os.Getenv("INSTANCE"), os.Getenv("DATABASE")))
	if err != nil {
		panic(err)
	}

	err = spannerdriver.RunTransaction(ctx, db, &sql.TxOptions{}, func(ctx context.Context, tx *sql.Tx) error {
		fmt.Println("Panicking")
		panic("panic")
	})
	if err != nil {
		panic(err)
	}

	fmt.Println("Done")
}

Expected output:

Panicking
panic: panic

followed by the process exiting.

Actual output:

Panicking

followed by the process hanging indefinitely.

Note that adding a call to tx.Rollback() within the function passed to RunTransaction fixes the hang. It seems that the outstanding transaction is causing the deferred call to conn.Close() within runTransactionWithOptions to hang indefinitely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions