Skip to content

Commit 6a22b89

Browse files
authored
Merge pull request #1885 from go-pg/fix/aborted-tx
Mark more errors as fatal
2 parents 0ffdbb7 + f7d17e9 commit 6a22b89

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

error.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ func isBadConn(err error, allowTimeout bool) bool {
4343
return false
4444
}
4545
if pgErr, ok := err.(Error); ok {
46-
return pgErr.Field('S') == "FATAL"
46+
switch pgErr.Field('V') {
47+
case "FATAL", "PANIC":
48+
return true
49+
}
50+
switch pgErr.Field('C') {
51+
case "25P02", // current transaction is aborted
52+
"57014": // canceling statement due to user request
53+
return true
54+
}
55+
return false
4756
}
4857
if allowTimeout {
4958
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {

tx_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var _ = Describe("Tx", func() {
135135
Expect(count).To(Equal(1))
136136

137137
err = tx1.Commit()
138-
Expect(err).NotTo(HaveOccurred()) // actually ROLLBACK happens here
138+
Expect(err).To(HaveOccurred()) // actually ROLLBACK happens here
139139

140140
_, err = tx2.QueryOne(pg.Scan(&count), "SELECT COUNT(*) FROM test_copy_from")
141141
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)