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

Appearance settings

Conversation

@njnu-seafish
Copy link
Contributor

Purpose of the pull request

close #17695

Brief change log

call statement.cancel method to cancel the procedure task

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

@SbloodyS SbloodyS added the improvement make more easy to user or prompt friendly label Nov 18, 2025
@SbloodyS SbloodyS added this to the 3.4.0 milestone Nov 18, 2025
@SbloodyS SbloodyS changed the title [Improvement-17695][ProcedureTask]Support cancel procedure task [Improvement-17695][ProcedureTask] Support cancel procedure task Nov 18, 2025
@github-actions github-actions bot added the test label Nov 19, 2025
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds cancellation support for procedure tasks by implementing the cancel() method to call Statement.cancel() on the active database statement. This allows procedure tasks to be interrupted during execution, similar to other task types like SQL tasks.

Key Changes

  • Implemented cancel() method in ProcedureTask to support task cancellation via Statement.cancel()
  • Added thread-safe volatile sessionStatement field to track the active statement for cancellation
  • Enhanced error handling to distinguish between cancelled and failed tasks
  • Added comprehensive unit tests covering various cancellation scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
ProcedureTask.java Implemented cancel() method with statement cancellation, added volatile sessionStatement field, and enhanced exception handling to check for EXIT_CODE_KILL
ProcedureTaskTest.java Added comprehensive unit tests for constructor validation, successful execution, error handling, cancellation scenarios, timeout configuration, and SQL formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines 143 to 144
stmt.cancel();
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The exit status code should be set to EXIT_CODE_KILL before attempting to cancel the statement. If stmt.cancel() throws an exception, the exit status will not be set, which could lead to incorrect task status reporting. Consider moving line 144 before line 143.

Suggested change
stmt.cancel();
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
stmt.cancel();

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exit status code should be set to EXIT_CODE_KILL before attempting to cancel the statement. If stmt.cancel() throws an exception, the exit status will not be set, which could lead to incorrect task status reporting. Consider moving line 144 before line 143.

good

Comment on lines 243 to 244
Integer exitCode = getPrivateField(procedureTask, "exitStatusCode");
assertEquals(exitCode, -1);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The test expects exitStatusCode to be -1 when cancel() throws an exception, but this contradicts the bug found in the implementation. According to line 144 of ProcedureTask.java, if stmt.cancel() throws an exception, setExitStatusCode() is never called, so the exit code remains at its previous value. The test assumption that it should be -1 is incorrect unless that's the default value. Consider verifying what the actual initial/default exit status code is, or update this test to reflect the actual behavior after fixing the implementation bug.

Suggested change
Integer exitCode = getPrivateField(procedureTask, "exitStatusCode");
assertEquals(exitCode, -1);
Integer exitCodeBefore = getPrivateField(procedureTask, "exitStatusCode");
Integer exitCodeAfter = getPrivateField(procedureTask, "exitStatusCode");
assertEquals(exitCodeAfter, exitCodeBefore, "exitStatusCode should remain unchanged when cancel() throws");

Copilot uses AI. Check for mistakes.
@Override
public void cancel() throws TaskException {

public void cancel() {
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The cancel() method signature was changed to remove the throws TaskException declaration, which is inconsistent with the parent class AbstractTask that declares public abstract void cancel() throws TaskException;. Even though the implementation throws TaskException on line 148, the signature should maintain the throws declaration for consistency with the parent class and other task implementations.

Suggested change
public void cancel() {
public void cancel() throws TaskException {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cancel() method signature was changed to remove the throws TaskException declaration, which is inconsistent with the parent class AbstractTask that declares public abstract void cancel() throws TaskException;. Even though the implementation throws TaskException on line 148, the signature should maintain the throws declaration for consistency with the parent class and other task implementations.

ok,good

private ResourceParametersHelper mockResourceHelper;

@Mock
private ProcedureParameters procedureParams = new ProcedureParameters();
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The @mock annotation should not be used with initialization. On line 73, procedureParams is annotated with @mock but also initialized with = new ProcedureParameters(). This is contradictory - either use @mock alone or remove the annotation and just instantiate. The initialization will be overwritten by Mockito anyway.

Suggested change
private ProcedureParameters procedureParams = new ProcedureParameters();
private ProcedureParameters procedureParams;

Copilot uses AI. Check for mistakes.
log.debug("this procedure task was canceled");
} catch (SQLException ex) {
log.warn("Failed to cancel stored procedure (driver/DB may not support it)", ex);
throw new TaskException("Cancel http task failed", ex);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".

Suggested change
throw new TaskException("Cancel http task failed", ex);
throw new TaskException("Cancel procedure task failed", ex);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".

nice

@SbloodyS SbloodyS modified the milestones: 3.4.0, 3.4.1 Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend improvement make more easy to user or prompt friendly test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][ProcedureTask] Support cancel procedure task

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.