diff --git a/lib/fed/decoder.go b/lib/fed/decoder.go
index db750827241552068d594801fb396e9499791693..8cafd3a6ed4b9aacf7fc7d4b7649fca9bdc410c7 100644
--- a/lib/fed/decoder.go
+++ b/lib/fed/decoder.go
@@ -39,6 +39,9 @@ func (T *Decoder) Reset(r io.Reader) {
 }
 
 func (T *Decoder) refill() error {
+	if T.bufferWrite >= len(T.buffer) {
+		return nil
+	}
 	n, err := T.reader.Read(T.buffer[T.bufferWrite:])
 	T.bufferWrite += n
 	return err
diff --git a/lib/fed/encoder.go b/lib/fed/encoder.go
index 6d88d48aee7fddaaeee1a6aae0298e4b831728c5..4daf795f1446d1a2a942bbd96058ea5937e6efd8 100644
--- a/lib/fed/encoder.go
+++ b/lib/fed/encoder.go
@@ -60,6 +60,9 @@ func (T *Encoder) ReadFrom(r *Decoder) (int, error) {
 }
 
 func (T *Encoder) Flush() error {
+	if T.bufferPos == 0 {
+		return nil
+	}
 	_, err := T.writer.Write(T.buffer[:T.bufferPos])
 	T.bufferPos = 0
 	return err
diff --git a/lib/gsql/query_test.go b/lib/gsql/query_test.go
index d19119e1096e46c86a30b998f0b50bd5620592c0..3839029d8ccc12b12a7d6e35c30d25220debe3a4 100644
--- a/lib/gsql/query_test.go
+++ b/lib/gsql/query_test.go
@@ -54,7 +54,10 @@ func TestQuery(t *testing.T) {
 
 	var b flip.Bank
 	b.Queue(func() error {
-		return gsql.ExtendedQuery(inward, &res, "SELECT usename, passwd FROM pg_shadow WHERE usename=$1", "postgres")
+		if err := gsql.ExtendedQuery(inward, &res, "SELECT usename, passwd FROM pg_shadow WHERE usename=$1", "postgres"); err != nil {
+			return err
+		}
+		return nil
 	})
 
 	b.Queue(func() error {
@@ -69,7 +72,10 @@ func TestQuery(t *testing.T) {
 		if serverErr != nil {
 			return serverErr
 		}
-		return outward.Close()
+		if err := outward.Close(); err != nil {
+			return err
+		}
+		return nil
 	})
 
 	if err = b.Wait(); err != nil {