Skip to content
Permalink
Browse files

fix issue 1547, as long as peek returns some bytes do not reset the t…

…imeout, this allows us to continue checking until any async notifies are consumed (#1548)
  • Loading branch information...
davecramer committed Aug 26, 2019
1 parent 0600990 commit 36a75cbaab4bda1b55f48aa9064258051cd89b10
Showing with 18 additions and 4 deletions.
  1. +18 −4 pgjdbc/src/main/java/org/postgresql/core/PGStream.java
@@ -115,25 +115,39 @@ public SocketFactory getSocketFactory() {
* @throws IOException if something wrong happens
*/
public boolean hasMessagePending() throws IOException {

boolean available = false;

// In certain cases, available returns 0, yet there are bytes
if (pgInput.available() > 0) {
return true;
}
// In certain cases, available returns 0, yet there are bytes
long now = System.currentTimeMillis();
long now = System.nanoTime() / 1000000;

if (now < nextStreamAvailableCheckTime && minStreamAvailableCheckDelay != 0) {
// Do not use ".peek" too often
return false;
}
nextStreamAvailableCheckTime = now + minStreamAvailableCheckDelay;

int soTimeout = getNetworkTimeout();
setNetworkTimeout(1);
try {
return pgInput.peek() != -1;
available = (pgInput.peek() != -1);
} catch (SocketTimeoutException e) {
return false;
} finally {
setNetworkTimeout(soTimeout);
}

/*
If none available then set the next check time
In the event that there more async bytes available we will continue to get them all
see issue 1547 https://github.com/pgjdbc/pgjdbc/issues/1547
*/
if (!available) {
nextStreamAvailableCheckTime = now + minStreamAvailableCheckDelay;
}
return available;
}

public void setMinStreamAvailableCheckDelay(int delay) {

0 comments on commit 36a75cb

Please sign in to comment.
You can’t perform that action at this time.