2
0

Fix deadlock when CopyFromSource panics

fixes #433
This commit is contained in:
Jack Christensen
2018-07-14 11:26:09 -05:00
parent 3cbe92ebb5
commit 20c02acd63
2 changed files with 101 additions and 27 deletions
+42
View File
@@ -426,3 +426,45 @@ func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
ensureConnValid(t, conn)
}
type nextPanicSource struct {
}
func (cfs *nextPanicSource) Next() bool {
panic("crash")
}
func (cfs *nextPanicSource) Values() ([]interface{}, error) {
return []interface{}{nil}, nil // should never get here
}
func (cfs *nextPanicSource) Err() error {
return nil // should never gets here
}
func TestConnCopyFromCopyFromSourceNextPanic(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo(
a bytea not null
)`)
caughtPanic := false
func() {
defer func() {
if x := recover(); x != nil {
caughtPanic = true
}
}()
conn.CopyFrom(pgx.Identifier{"foo"}, []string{"a"}, &nextPanicSource{})
}()
if conn.IsAlive() {
t.Error("panic should have killed conn")
}
}