Skip to content

Restore interrupt status in InterruptedException catch blocks - #13074

Open
TimurRakhmatullin86 wants to merge 1 commit into
grpc:masterfrom
TimurRakhmatullin86:fix/restore-interrupt-status-on-catch
Open

TimurRakhmatullin86 wants to merge 1 commit into
grpc:masterfrom
TimurRakhmatullin86:fix/restore-interrupt-status-on-catch

Conversation

@TimurRakhmatullin86

Copy link
Copy Markdown
Contributor

Summary

Six files catch InterruptedException, wrap it in another exception, and
re-throw without calling Thread.currentThread().interrupt() first. This
silently clears the thread's interrupt flag, preventing callers from detecting
that an interrupt occurred.

The rest of the codebase already follows the correct pattern (e.g.,
ClientCalls, NettyServer, OkHttpClientTransport, CsdsService,
AsyncSecurityPolicy): restore the flag before re-throwing.

Files fixed

File Catch blocks What was wrong
TransmitStatusRuntimeExceptionInterceptor 4 Wrapped in RuntimeException without restore
AltsHandshakerClient 3 Multi-catch with IOException, wrapped in GeneralSecurityException without restore
HandshakerServiceChannel 1 Completely swallowed in close() without flag restore
ChannelzProtoUtil 1 Wrapped in StatusRuntimeException without restore
XdsServerWrapper 1 Multi-catch with ExecutionException, wrapped in RuntimeException without restore
SslContextFactory 1 Multi-catch with IOException, wrapped in GeneralSecurityException without restore

For multi-catch blocks (IOException | InterruptedException), the catch is
split so that Thread.currentThread().interrupt() is called only for
InterruptedException, not for IOException.

Test plan

  • No behavioral change for non-interrupted threads — the re-throw path is identical
  • Matches the existing pattern used throughout the codebase
  • Existing tests pass (no new tests needed — the fix is mechanical)

🤖 Generated with Claude Code

Six files catch InterruptedException, wrap it in another exception, and
re-throw without first calling Thread.currentThread().interrupt().  This
silently clears the thread's interrupt flag, so callers checking
Thread.isInterrupted() will miss that an interrupt occurred.

The rest of the codebase (ClientCalls, NettyServer, OkHttpClientTransport,
CsdsService, AsyncSecurityPolicy, etc.) already follows the correct
pattern: restore the flag, then re-throw.  These six are oversights.

Files fixed:
- TransmitStatusRuntimeExceptionInterceptor (4 catch blocks)
- AltsHandshakerClient (3 catch blocks, split from multi-catch)
- HandshakerServiceChannel (1 catch block in close())
- ChannelzProtoUtil (1 catch block)
- XdsServerWrapper (1 catch block, split from multi-catch)
- SslContextFactory (1 catch block, split from multi-catch)

This branch has not been deployed

No deployments
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.

1 participant