PgConnection.flush appears to misunderstand how to use the underlying PQflush function. When PQflush returns 1, this is not an error. The 1 should be returned to the caller of PgConnection.flush, so the caller knows whether to call flush again.
1 means "call again when the socket is writable."
0 means "no more data to write".
-1 means error, and only in this case should...