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

defer rowss.Close() bug while cross compiling from windows to linux #29783

Closed
pizzalord22 opened this issue Jan 17, 2019 · 1 comment
Closed

Comments

@pizzalord22
Copy link

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

1.11.4

Does this issue reproduce with the latest release?

yes

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

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\markjoling\AppData\Local\go-build
set GOEXE=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=linux
set GOPATH=C:\Users\markjoling\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=C:\Users\MARKJO~1\AppData\Local\Temp\go-build119513918=/tmp/go-build -gno-record-gcc-switches

What did you do?

link to bugged code and work around
https://play.golang.org/p/TO4a4QtnPSa

What did you expect to see?

i exepected rows.Next() to run.

What did you see instead?

rows.Next() did not execute

@josharian
Copy link
Contributor

The arguments to a deferred function are evaluated immediately. So when you write defer erh.Check(rows.Close()), rows.Close() is evaluated immediately. This closes rows, so rows.Next doesn't return anything. Instead, do defer func() { erh.Check(rows.Close()) }().

@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants