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

Fix interrupt handling #272

Merged
merged 1 commit into from
Apr 24, 2024
Merged

Conversation

avijeet95
Copy link
Contributor

@avijeet95 avijeet95 commented Apr 23, 2024

Changes

Current implementation does not work well when client interrupts a thread where SDK code is running. Once interrupted, the logic continues to run till the timeout (default 20mins) without sleeping at all. Each time thread.sleep is called, it throws interrupt exception and this results in calling the status API continuously without delay.

The PR is changing the handling to throw DatabricksException when the thread is interrupted so that clients can stop the processing and handle the exception as they wish.

Tests

All unit tests are successful.

@avijeet95 avijeet95 requested a review from tanmay-db April 23, 2024 10:37
@avijeet95 avijeet95 added the Bug The issue is a bug. label Apr 23, 2024
@avijeet95 avijeet95 requested a review from mgyucht April 23, 2024 11:07
Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

Do you need to do the same in ApiClient.java?

@@ -95,7 +95,7 @@ public class {{.PascalName}}API {
try {
Thread.sleep((long) (sleep * 1000L + Math.random() * 1000));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new DatabricksException("Current thread was interrupted", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

You have to call Thread.currentThread().interrupt() to reset the interrupted bit so that callers will know that this thread was interrupted and can handle such a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that we are already throwing an exception which should be handled by the callers. But I think it won't harm to reset the flag. Just in case someone suppresses the exception, it will still flag the thread as interrupted.

@avijeet95
Copy link
Contributor Author

Do you need to do the same in ApiClient.java?

Thanks for catching this. I'll update it as well.

@avijeet95 avijeet95 force-pushed the fix-interrupt-handling branch from cc4f56c to bf74ba0 Compare April 24, 2024 07:58
@avijeet95 avijeet95 requested a review from mgyucht April 24, 2024 08:01
@mgyucht mgyucht enabled auto-merge April 24, 2024 08:21
auto-merge was automatically disabled April 24, 2024 08:44

Head branch was pushed to by a user without write access

@avijeet95 avijeet95 force-pushed the fix-interrupt-handling branch 5 times, most recently from 03e2351 to bba0619 Compare April 24, 2024 08:54
@avijeet95 avijeet95 force-pushed the fix-interrupt-handling branch from bba0619 to 88d8b6a Compare April 24, 2024 09:00
@mgyucht mgyucht added this pull request to the merge queue Apr 24, 2024
Merged via the queue into databricks:main with commit b06c626 Apr 24, 2024
9 checks passed
@avijeet95 avijeet95 deleted the fix-interrupt-handling branch April 24, 2024 09:26
tanmay-db added a commit that referenced this pull request Apr 24, 2024
* Fix interrupt handling ([#272](#272)).
* [PECO-1598] Add README for proxy and minor fix ([#273](#273)).
@tanmay-db tanmay-db mentioned this pull request Apr 24, 2024
github-merge-queue bot pushed a commit that referenced this pull request Apr 24, 2024
* Fixed interrupt handling
([#272](#272)).
* Added README for proxy and minor fix
([#273](#273)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue is a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants