Skip to content

fix: properly handle thread interrupts during gRPC channel shutdown#159

Merged
KaviarasuSakthivadivel merged 2 commits intomainfrom
fix/grpc-channel-interrupt-handling
Mar 5, 2026
Merged

fix: properly handle thread interrupts during gRPC channel shutdown#159
KaviarasuSakthivadivel merged 2 commits intomainfrom
fix/grpc-channel-interrupt-handling

Conversation

@KaviarasuSakthivadivel
Copy link
Contributor

@KaviarasuSakthivadivel KaviarasuSakthivadivel commented Mar 5, 2026

When InterruptedException is caught during channel.awaitTermination(),
the thread's interrupt status is cleared. This fix restores the interrupt
status following Java best practices to ensure proper interrupt propagation.

Changes:

  • Restore interrupt status with Thread.currentThread().interrupt()
  • Improve logging to distinguish timeout from interrupt

This ensures thread pools and upstream callers can properly detect
that the thread was interrupted.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.79%. Comparing base (97bc515) to head (26fd1ac).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #159      +/-   ##
============================================
+ Coverage     82.73%   82.79%   +0.06%     
  Complexity     1347     1347              
============================================
  Files           111      111              
  Lines          4055     4058       +3     
  Branches        413      413              
============================================
+ Hits           3355     3360       +5     
+ Misses          510      508       -2     
  Partials        190      190              
Components Coverage Δ
JDBC Core 83.98% <100.00%> (+0.07%) ⬆️
JDBC Main 40.69% <ø> (ø)
JDBC HTTP 91.09% <ø> (ø)
JDBC Utilities 66.07% <ø> (ø)
Spark Datasource ∅ <ø> (∅)
Files with missing lines Coverage Δ
...ce/datacloud/jdbc/core/JdbcDriverStubProvider.java 94.11% <100.00%> (+15.54%) ⬆️

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KaviarasuSakthivadivel KaviarasuSakthivadivel force-pushed the fix/grpc-channel-interrupt-handling branch 2 times, most recently from d241348 to 46d1504 Compare March 5, 2026 21:27
When InterruptedException is caught during channel.awaitTermination(),
the thread's interrupt status is cleared. This fix restores the interrupt
status following Java best practices to ensure proper interrupt propagation.

Changes:
- Call shutdownNow() immediately when interrupted
- Restore interrupt status with Thread.currentThread().interrupt()
- Improve logging to distinguish timeout from interrupt
- Follow pattern from gRPC Java examples

This ensures thread pools and upstream callers can properly detect
that the thread was interrupted.
@KaviarasuSakthivadivel KaviarasuSakthivadivel force-pushed the fix/grpc-channel-interrupt-handling branch from 46d1504 to 0f4674f Compare March 5, 2026 21:46
When InterruptedException is caught during channel.awaitTermination(),
the thread's interrupt status is cleared. This fix restores the interrupt
status following Java best practices to ensure proper interrupt propagation.

Changes:
- Use graceful shutdown() to allow async queries to complete on server
- Call shutdownNow() immediately when interrupted or on timeout
- Restore interrupt status with Thread.currentThread().interrupt()
- Improve logging to distinguish timeout from interrupt scenarios

This hybrid approach:
- Supports async query patterns (submit query, close connection, fetch later)
- Fixes interrupt handling for thread pool shutdowns
- Ensures proper interrupt propagation to upstream callers
@KaviarasuSakthivadivel KaviarasuSakthivadivel merged commit b0a96d1 into main Mar 5, 2026
21 of 23 checks passed
@KaviarasuSakthivadivel KaviarasuSakthivadivel deleted the fix/grpc-channel-interrupt-handling branch March 5, 2026 23:58
KaviarasuSakthivadivel pushed a commit that referenced this pull request Mar 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.42.2](v0.42.1...v0.42.2)
(2026-03-05)


### Bug Fixes

* allow refresh-token auth without userName
([#157](#157))
([97bc515](97bc515))
* properly handle thread interrupts during gRPC channel shutdown
([#159](#159))
([b0a96d1](b0a96d1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

4 participants