Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: avoid IllegalStateException: Timer already cancelled when StatementCancelTimerTask.run throws a runtime error#3778

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vlsi merged 2 commits intopgjdbc:masterfromvlsi:cancel
Sep 18, 2025

Conversation

vlsi
Copy link
Member

Previously, StatementCancelTimerTask might propagate runtime errors to java.util.Timer which causes the Timer to cancel itself. We don't want that behavior, so we should avoid throwing errors from TimerTask implementations.

Note statement.cancelIfStillNeeded has already been ignoring SQLExceptions from statement.cancel() for quite a while, however, it did not ignore runtime errors.

Fixes#3530

@vlsivlsi added the bug labelAug 20, 2025
@vlsivlsi changed the titlefix: ensure that StatementCancelTimerTask.run does not propagate errorsfix: avoid IllegalStateException: Timer already cancelled when StatementCancelTimerTask.run throws a runtime errorAug 20, 2025
@lfgcampos
Copy link

Hi@vlsi, those are amazing news!

Is there any explanation though why it works onv42.7.4 but not on others?
I tried to look into the changes and changelog but can't really understand what/when this problem was introduced.

@davecramer
Copy link
Member

LGTM, this will be difficult to test.

@vlsi
Copy link
MemberAuthor

I'm leaning towards adding a test with mock that triggers an exception from.cancel()
Will try adding it shortly.


Is there any explanation though why it works on v42.7.4 but not on others?

bac3d0a landed at 42.7.6, and it changedint tobyte[]. Previously, an unsetcancelKey was just0, so it did not cause any harm. After PR#3592 thenullbyte[] could cause NPE.
Interestingly,castNonNull caused NPE, so writing code in a way that does not requirecastNotNull seems the right way to go.

At the same time, backend should always supplycancel key in the startup messages, so I don't understand how is it possible that you havenullcancelKey. I wonder if you could capture logging fororg.postgresql.core.QueryExecutorBase in order to check if it does indeed end up with null cancel keys.
Do you use a load balancer?

It does not explain the reason 42.7.5 fails though. Just to double-check: does 42.7.5 fail for you as well?

lfgcampos reacted with thumbs up emoji

@lfgcampos
Copy link

I'm leaning towards adding a test with mock that triggers an exception from.cancel() Will try adding it shortly.

Is there any explanation though why it works on v42.7.4 but not on others?

bac3d0a landed at 42.7.6, and it changedint tobyte[]. Previously, an unsetcancelKey was just0, so it did not cause any harm. After PR#3592 thenullbyte[] could cause NPE. Interestingly,castNonNull caused NPE, so writing code in a way that does not requirecastNotNull seems the right way to go.

At the same time, backend should always supplycancel key in the startup messages, so I don't understand how is it possible that you havenullcancelKey. I wonder if you could capture logging fororg.postgresql.core.QueryExecutorBase in order to check if it does indeed end up with null cancel keys. Do you use a load balancer?

It does not explain the reason 42.7.5 fails though. Just to double-check: does 42.7.5 fail for you as well?

We bumped from~.4 to~.7 so I can't say if the~.5 works or not.

Some info that may or may not help:

  • yes, we have as LB and RDS Proxy
  • we are using a mix of quarkus/pure java, meaning our connections are also a mix of hikari and agroal

Regarding capturing the log fororg.postgresql.core.QueryExecutorBase, that is a tricky one since the bump caused a couple of hours long outage on our prod
Also, quite interesting, it does not happen on dev - probably related to the timeout after all, it would at least explain it

@vlsi
Copy link
MemberAuthor

vlsi commentedAug 22, 2025
edited
Loading

that is a tricky one since the bump caused a couple of hours long outage on our prod

Sorry to hear that.
I mean the log would be helpful for either old or new (after the cancellation issue gets fixed) version.
The old (e.g. 42.7.4) logs the key:https://github.com/pgjdbc/pgjdbc/blob/REL42.7.4/pgjdbc/src/main/java/org/postgresql/core/QueryExecutorBase.java#L190

I wonder ifckey={1} comes out as0.
Sure there's no hurry to logging it, however, if the cancellation key is not set, then it might be the cancellation does not work in your case. It might be caused by the balancer chewing the cancellation key from within the startup message.

An alternative option would be trying to executepg_sleep(..)including your balancers and proxies, to verify if you can getPSQLException: ERROR: canceling statement due to user request whensetQueryTimeout(...) kicks in.

@vlsivlsiforce-pushed thecancel branch 3 times, most recently fromb2fa0a3 toe696d2fCompareSeptember 18, 2025 19:31
…entCancelTimerTask.run throws a runtime errorPreviously, StatementCancelTimerTask might propagate runtime errorsto java.util.Timer which causes the Timer to cancel itself.We don't want that behavior, so we should avoid throwing errors from TimerTaskimplementations.Note statement.cancelIfStillNeeded has already been ignoring SQLExceptions fromstatement.cancel() for quite a while, however, it did not ignore runtime errors.Fixespgjdbc#3530
@vlsivlsi merged commit3d97bb8 intopgjdbc:masterSep 18, 2025
8 of 9 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

JDBC Shared Timer set to cancelled
3 participants
@vlsi@lfgcampos@davecramer

[8]ページ先頭

©2009-2025 Movatter.jp