Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: rollback is freezing if rows not be closed #20575

Closed
kshvakov opened this issue Jun 5, 2017 · 3 comments
Closed

database/sql: rollback is freezing if rows not be closed #20575

kshvakov opened this issue Jun 5, 2017 · 3 comments
Assignees

Comments

@kshvakov
Copy link

@kshvakov kshvakov commented Jun 5, 2017

What version of Go are you using (go version)?

go version devel +b225051 Mon Jun 5 02:35:47 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/kshvakov/gopath"
GORACE=""
GOROOT="/home/kshvakov/go"
GOTOOLDIR="/home/kshvakov/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build025114464=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/lib/pq"
)

func main() {
	connect, err := sql.Open("postgres", "postgres://test@127.0.0.1:5432/example?sslmode=disable")
	checkErr(err)
	if tx, err := connect.Begin(); err == nil {
		if _, err = tx.Query("SELECT 1"); err == nil {
			// rows.Close()
			fmt.Println("rollback")
			tx.Rollback()
			fmt.Println("rollback: done!")
		}
		_, err = tx.Query("SELECT 1")
		fmt.Println(err)
	}
}

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

What did you expect to see?

rollback
rollback: done!
sql: Transaction has already been committed or rolled back

What did you see instead?

rollback
@odeke-em
Copy link
Member

@odeke-em odeke-em commented Jun 5, 2017

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 5, 2017

CL https://golang.org/cl/44812 mentions this issue.

@kardianos kardianos self-assigned this Jun 5, 2017
@kardianos
Copy link
Contributor

@kardianos kardianos commented Jun 5, 2017

I agree that this is an issue, though a case could be made this is a coding error. I've send the above CL which would alter the behavior so the Rows will be closed if the parent Tx is closed in any way while it is open.

@gopherbot gopherbot closed this in 729685c Jun 5, 2017
@golang golang locked and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.