mirror of https://github.com/jackc/pgx.git
Unit test demonstrating infinite loop
Hi, I have just created a unit test demonstrating an infinite loop during cleanup in a defered function. The CPU will just sit at 100% use. I know this is a special case, but it's would be nice if a buggy Scanner doesn't make cleanup functions like rows.Close run indefinitely. Sadly, I'm not sure how to fix/improve this.pull/77/head
parent
654508050c
commit
e511c267de
|
@ -223,6 +223,37 @@ func TestArrayDecoding(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type buggyScanner struct {}
|
||||
|
||||
func (*buggyScanner) Scan(r *pgx.ValueReader) error {
|
||||
r.ReadInt32()
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestBuggyScanner(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnect(t, *defaultConnConfig)
|
||||
defer closeConn(t, conn)
|
||||
|
||||
rows, err := conn.Query("select 'tevvvvvzvzst', array[]::text[] union select 'ko', array[]::text[]")
|
||||
if err != nil {
|
||||
t.Errorf(`error retrieving rows with array: %v`, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var s string
|
||||
var b buggyScanner
|
||||
err = rows.Scan(&s, &b)
|
||||
if err != nil {
|
||||
t.Errorf(`error reading array: %v`, err)
|
||||
}
|
||||
}
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestEmptyArrayDecoding(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue