Skip to content

Commit

Permalink
ListenerConn: Return l.err instead of EOF on query failure
Browse files Browse the repository at this point in the history
While io.EOF is not the worst choice here, it can be a bit misleading.
Fix by providing the accurate error (which should always be set at this
point).
  • Loading branch information
johto committed May 2, 2015
1 parent 00f549c commit 40e0272
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package pq
import (
"errors"
"fmt"
"io"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -144,6 +143,9 @@ func (l *ListenerConn) listenerConnLoop() (err error) {
// about the scratch buffer being overwritten.
l.notificationChan <- recvNotification(r)

case 'T', 'D':
// only used by tests; ignore

case 'E':
// We might receive an ErrorResponse even when not in a query; it
// is expected that the server will close the connection after
Expand Down Expand Up @@ -296,8 +298,11 @@ func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) {
m, ok := <-l.replyChan
if !ok {
// We lost the connection to server, don't bother waiting for a
// a response.
return false, io.EOF
// a response. err should have been set already.
l.connectionLock.Lock()
err := l.err
l.connectionLock.Unlock()
return false, err
}
switch m.typ {
case 'Z':
Expand Down

0 comments on commit 40e0272

Please sign in to comment.