Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isValid() timeout should not be blocked #1943

Merged
merged 1 commit into from Nov 12, 2020
Merged

isValid() timeout should not be blocked #1943

merged 1 commit into from Nov 12, 2020

Conversation

hugomiguelabreu
Copy link
Contributor

@hugomiguelabreu hugomiguelabreu commented Oct 22, 2020

The usage of setQueryTimeout(); with the same value as the setNetworkTimeout(); is blocking the current transaction timeout.
The timeouts are blocking each other with this approach.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Does ./gradlew autostyleCheck checkstyleAll pass ?
  3. Have you added your new test classes to an existing test suite in alphabetical order?

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

@davecramer
Copy link
Member

how does this work ? Why does setting the time out there block the other one ?

@hugomiguelabreu
Copy link
Contributor Author

hugomiguelabreu commented Oct 22, 2020

Hey @davecramer.
From my thread dump and slight investigation, by using the setQueryTimeout() when the database is down, when calling isValid() you'll have a thread trying to kill the task using the killTimerTask(); (line 1022 - PgStatement) because the connection timed out as expected, but not being able to because the connection is stuck trying to cancel it connection.cancelQuery();(line 908 - PgStatement).

Ultimately the synchronized block doesn't allow the killTimerTask(); proceed since the connection.cancelQuery(); is using the connection and is stuck trying to cancel it, since when you cancel a query you are expecting to receive a cancelStream.receiveEOF(); that will never be fulfilled since the database is down.

@davecramer
Copy link
Member

got it, thx

@davecramer
Copy link
Member

I am wondering if we can create a test for this ?

@hugomiguelabreu
Copy link
Contributor Author

I am wondering if we can create a test for this ?

Sure we can. Let me get a bit more context on the tests on the repo and soon I'll send a new one!

@davecramer
Copy link
Member

Awesome, thanks!

@davecramer davecramer closed this Oct 23, 2020
@davecramer davecramer reopened this Oct 23, 2020
@codecov-io
Copy link

codecov-io commented Oct 23, 2020

Codecov Report

Merging #1943 into master will increase coverage by 4.03%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master    #1943      +/-   ##
============================================
+ Coverage     65.35%   69.39%   +4.03%     
- Complexity     3955     4228     +273     
============================================
  Files           197      197              
  Lines         18006    18004       -2     
  Branches       2919     2919              
============================================
+ Hits          11768    12494     +726     
+ Misses         4878     4158     -720     
+ Partials       1360     1352       -8     

@hugomiguelabreu
Copy link
Contributor Author

I've coded a regression test to make sure that isValid() respects the timeout.
I've written some javadoc although I think other test don't have it. I feel that it helps a lot to understand what the test is doing.

The usage of `setQueryTimeout();` with the same value as the `setNetworkTimeout();` is blocking the current transaction timeout.
The timeouts are blocking each other with this approach.
@vlsi
Copy link
Member

vlsi commented Oct 26, 2020

@hugomiguelabreu
Copy link
Contributor Author

It can be helpful for this specific test, nevertheless it's for this specific case, a more overview of the project tests should be analyzed.

@davecramer
Copy link
Member

@vlsi we should probably backpatch this.

@davecramer davecramer merged commit 7e2cd55 into pgjdbc:master Nov 12, 2020
hugomiguelabreu added a commit to hugomiguelabreu/pgjdbc that referenced this pull request Feb 24, 2021
The usage of `setQueryTimeout();` with the same value as the `setNetworkTimeout();` is blocking the current transaction timeout.
The timeouts are blocking each other with this approach.
davecramer pushed a commit that referenced this pull request Feb 25, 2021
The usage of `setQueryTimeout();` with the same value as the `setNetworkTimeout();` is blocking the current transaction timeout.
The timeouts are blocking each other with this approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants