Skip to content

http: allow opting out of interrupt-on-cancel for blocking services - #3632

Closed
daschl wants to merge 1 commit into
apple:mainfrom
daschl:interrupt-on-cancel-context-key
Closed

http: allow opting out of interrupt-on-cancel for blocking services#3632
daschl wants to merge 1 commit into
apple:mainfrom
daschl:interrupt-on-cancel-context-key

Conversation

@daschl

@daschl daschl commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

When a response is cancelled, for example because the client disconnected or a timeout fired, ServiceTalk interrupts the thread running a listenBlocking or listenBlockingStreaming service. There is no way to opt out. Applications whose blocking code cannot tolerate an interrupt, or that use libraries which respond to one by closing shared resources, have no recourse.

Modifications

  • Add HttpContextKeys.INTERRUPT_BLOCKING_SERVICE_ON_CANCEL, a request context key that disables the interrupt when set to false.
  • Honor it in the blocking and blocking-streaming service adapters.
  • Add InterruptBlockingServiceOnCancelHttpServiceFilter to http-utils for setting it, which also covers routers and gRPC services because they build on the same adapters.

Result

Blocking services can opt out of interrupt-on-cancel per request. The default is unchanged, so absent the key the thread is still interrupted.

With the interrupt disabled a blocking-streaming service still observes cancellation cooperatively, because its payload writer is terminated and the next write fails. An aggregated blocking service has no such signal and runs to completion, so the option should only be used by services that cannot block indefinitely.

No API compatibility impact; the context key and the filter are additions.

Motivation

Modifications

Result

#### Motivation

When a response is cancelled, for example because the client disconnected or a
timeout fired, ServiceTalk interrupts the thread running a `listenBlocking` or
`listenBlockingStreaming` service. There is no way to opt out. Applications
whose blocking code cannot tolerate an interrupt, or that use libraries which
respond to one by closing shared resources, have no recourse.

#### Modifications

- Add `HttpContextKeys.INTERRUPT_BLOCKING_SERVICE_ON_CANCEL`, a request context
  key that disables the interrupt when set to `false`.
- Honor it in the blocking and blocking-streaming service adapters.
- Add `InterruptBlockingServiceOnCancelHttpServiceFilter` to `http-utils` for
  setting it, which also covers routers and gRPC services because they build on
  the same adapters.

#### Result

Blocking services can opt out of interrupt-on-cancel per request. The default is
unchanged, so absent the key the thread is still interrupted.

With the interrupt disabled a blocking-streaming service still observes
cancellation cooperatively, because its payload writer is terminated and the
next write fails. An aggregated blocking service has no such signal and runs to
completion, so the option should only be used by services that cannot block
indefinitely.

No API compatibility impact; the context key and the filter are additions.
@daschl daschl closed this Sep 8, 2026
@daschl

daschl commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

see #3635

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