Skip to content

Closes #448 - Fix C7 Locking-Query Parameter-Binding#451

Open
bruderj15 wants to merge 3 commits into
masterfrom
task/#448-add-tests-c7-locking-clustering
Open

Closes #448 - Fix C7 Locking-Query Parameter-Binding#451
bruderj15 wants to merge 3 commits into
masterfrom
task/#448-add-tests-c7-locking-clustering

Conversation

@bruderj15

@bruderj15 bruderj15 commented May 6, 2026

Copy link
Copy Markdown
Member

Definition of Done

  • The corresponding ticket is in state In Review
  • The corresponding ticket is attached to this Pull-Request
  • The commit-message-format Closes #ISSUE_ID - PROBLEM/SOLUTION
    • is present as single-commit already or
    • will be squashed on merge
  • The changes pass the SonarQubeCloud-Quality-Gate
  • If the documentation needs an update, following there's a link to it:
  • If extra release-notes are required, they're listed indented below:

@bruderj15 bruderj15 marked this pull request as ready for review May 6, 2026 07:55
@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown

Comment on lines 165 to 171
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, remainingRetries);
if (lockDuration != null) {
preparedStatement.setTimestamp(1, Timestamp.from(Instant.now()));
preparedStatement.setTimestamp(2, Timestamp.from(Instant.now()));
}
ResultSet camundaTaskEventFilteredByRetriesResultSet = preparedStatement.executeQuery();
camunda7TaskEventsFilteredByRetries =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most critical finding.
Wrong Parameter-Binding did not set lock_expire < ? but falsely remaining_retires = ?.

Here is e.g. the Oracle prepared statement query:

  public String getAvailableEventsFilteredByRetries(String schema) {
    final String sql =
        "select * from %s.event_store where remaining_retries = ? and (lock_expire "
            + "< ? or lock_expire is null) for update skip locked";
    return String.format(sql, schema);

I wonder here: this should have errored out due to non-binded parameter.
Yet the queries succeeded - signaling a default being set.
Depending on the default this may explain the observed bug with multiple Adapter-instances running in a cluster and processing the same events.

Debug-Logs of actually executed queries will help here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensive studies revealed that that code-path isn't walked without Example/Test-Setup.
Hence why the expected SQL-Binding error never came up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the default this may explain the observed bug with multiple Adapter-instances running in a cluster and processing the same events.

This can therefore be ruled out.
Subsequent PRs to highly likely show reason for the bug being wrong transaction boundaries.

Comment on lines 31 to 36
@Override
public String getAvailableEventsFilteredByRetries(String schema) {
final String sql =
"select * from %s.event_store where remaining_retries = ? and lock_expire "
+ "< ? or lock_expire is null for update skip locked data";
"select * from %s.event_store where remaining_retries = ? and (lock_expire "
+ "< ? or lock_expire is null) for update skip locked data";
return String.format(sql, schema);

@bruderj15 bruderj15 May 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong precedence for all providers.
Probably not related to aforementioned bug - still semantically wrong query.

@leantios leantios self-requested a review June 19, 2026 10:42
@leantios

Copy link
Copy Markdown
Contributor

Well done and looks good so far. Do the added tests fail without your changes?

@bruderj15

Copy link
Copy Markdown
Member Author

Well done and looks good so far. Do the added tests fail without your changes?

Yeah they do.

See https://github.com/kadai-io/KadaiAdapter/actions/runs/27818009070/job/82324158828 of sibling PR

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.

Wrong JDBC Parameter-Binding in Camunda7TaskEventService::getEventsFilteredByRetries

2 participants