Skip to content

no panic on closed connection reuse #143

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

Merged
merged 3 commits into from
Oct 30, 2013

Conversation

arnehormann
Copy link
Member

Closes #142

I'm not sure if this is good to go yet. The test should probably be expanded, it doesn't test all cases I fixed.
Let's take it as a basis for a discussion.

I didn't see a central place to add the checks and I'm not sure if I missed some relevant ones.

How this was created:
I located the places to fix by searching for mysql(Stmt|Conn|Tx|Rows)\) [A-Z] in all go files. Those are the only structs containing (or beeing) mysqlConn, the exported functions as entry points should suffice for the check and make sure it's not "overchecked".

I changed the mc.netConn checks to mc.buf in existing code to keep the checked condition the same everywhere. I did not check the disassembled object code for this being faster than comparing mc.netConn == nil or writing a small func which is or is not inlined.

@julienschmidt
Copy link
Member

http://play.golang.org/p/tGf3r4UtFS

BenchmarkPerfCheckBuf   2000000000               0.59 ns/op
BenchmarkPerfCheckConn  2000000000               0.59 ns/op
BenchmarkPerfCheckCfg   2000000000               0.59 ns/op

--- prog list "BenchmarkPerfCheckBuf" ---
0000 (perf_test.go:19) TEXT    BenchmarkPerfCheckBuf+0(SB),$0-8
0001 (perf_test.go:19) MOVQ    b+0(FP),SI
0002 (perf_test.go:19) MOVQ    someConn+0(SB),DX
0003 (perf_test.go:19) FUNCDATA $0,gcargs┬À0+0(SB)
0004 (perf_test.go:19) FUNCDATA $1,gclocals┬À0+0(SB)
0005 (perf_test.go:19) TYPE    b+0(FP){*testing.B},$8
0006 (perf_test.go:20) MOVQ    $0,AX
0007 (perf_test.go:20) JMP     ,9
0008 (perf_test.go:20) INCQ    ,AX
0009 (perf_test.go:20) NOP     ,
0010 (perf_test.go:20) MOVQ    112(SI),BX
0011 (perf_test.go:20) CMPQ    BX,AX
0012 (perf_test.go:20) JLE     $0,20
0013 (perf_test.go:21) NOP     ,
0014 (perf_test.go:21) MOVQ    32(DX),BX
0015 (perf_test.go:21) MOVQ    $0,BP
0016 (perf_test.go:21) CMPQ    BX,BP
0017 (perf_test.go:21) JEQ     ,8
0018 (perf_test.go:22) MOVQ    $1,CX
0019 (perf_test.go:21) JMP     ,8
0020 (perf_test.go:25) RET     ,

--- prog list "BenchmarkPerfCheckConn" ---
0021 (perf_test.go:27) TEXT    BenchmarkPerfCheckConn+0(SB),$0-8
0022 (perf_test.go:27) MOVQ    b+0(FP),SI
0023 (perf_test.go:27) MOVQ    someConn+0(SB),DX
0024 (perf_test.go:27) FUNCDATA $0,gcargs┬À1+0(SB)
0025 (perf_test.go:27) FUNCDATA $1,gclocals┬À1+0(SB)
0026 (perf_test.go:27) TYPE    b+0(FP){*testing.B},$8
0027 (perf_test.go:28) MOVQ    $0,AX
0028 (perf_test.go:28) JMP     ,30
0029 (perf_test.go:28) INCQ    ,AX
0030 (perf_test.go:28) NOP     ,
0031 (perf_test.go:28) MOVQ    112(SI),BX
0032 (perf_test.go:28) CMPQ    BX,AX
0033 (perf_test.go:28) JLE     $0,39
0034 (perf_test.go:29) NOP     ,
0035 (perf_test.go:29) CMPQ    16(DX),$0
0036 (perf_test.go:29) JEQ     ,29
0037 (perf_test.go:30) MOVQ    $1,CX
0038 (perf_test.go:29) JMP     ,29
0039 (perf_test.go:33) RET     ,

--- prog list "BenchmarkPerfCheckCfg" ---
0040 (perf_test.go:35) TEXT    BenchmarkPerfCheckCfg+0(SB),$0-8
0041 (perf_test.go:35) MOVQ    b+0(FP),SI
0042 (perf_test.go:35) MOVQ    someConn+0(SB),DX
0043 (perf_test.go:35) FUNCDATA $0,gcargs┬À2+0(SB)
0044 (perf_test.go:35) FUNCDATA $1,gclocals┬À2+0(SB)
0045 (perf_test.go:35) TYPE    b+0(FP){*testing.B},$8
0046 (perf_test.go:36) MOVQ    $0,AX
0047 (perf_test.go:36) JMP     ,49
0048 (perf_test.go:36) INCQ    ,AX
0049 (perf_test.go:36) NOP     ,
0050 (perf_test.go:36) MOVQ    112(SI),BX
0051 (perf_test.go:36) CMPQ    BX,AX
0052 (perf_test.go:36) JLE     $0,60
0053 (perf_test.go:37) NOP     ,
0054 (perf_test.go:37) MOVQ    (DX),BX
0055 (perf_test.go:37) MOVQ    $0,BP
0056 (perf_test.go:37) CMPQ    BX,BP
0057 (perf_test.go:37) JEQ     ,48
0058 (perf_test.go:38) MOVQ    $1,CX
0059 (perf_test.go:37) JMP     ,48
0060 (perf_test.go:41) RET     ,

@@ -108,6 +108,40 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
return rows
}

func TestClosedConnection(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestReuseClosedConnection

@arnehormann
Copy link
Member Author

I won't merge until you LGTM it again because I don't handle err == nil separately.
PTAL

@julienschmidt
Copy link
Member

LGTM

arnehormann added a commit that referenced this pull request Oct 30, 2013
no panic on closed connection reuse
@arnehormann arnehormann merged commit 2a93d21 into go-sql-driver:master Oct 30, 2013
@arnehormann arnehormann deleted the no-panic branch October 30, 2013 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when a closed connnection is used
2 participants