http: allow opting out of interrupt-on-cancel for blocking services - #3632
Closed
daschl wants to merge 1 commit into
Closed
http: allow opting out of interrupt-on-cancel for blocking services#3632daschl wants to merge 1 commit into
daschl wants to merge 1 commit into
Conversation
#### 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.
Contributor
Author
|
see #3635 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When a response is cancelled, for example because the client disconnected or a timeout fired, ServiceTalk interrupts the thread running a
listenBlockingorlistenBlockingStreamingservice. 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
HttpContextKeys.INTERRUPT_BLOCKING_SERVICE_ON_CANCEL, a request context key that disables the interrupt when set tofalse.InterruptBlockingServiceOnCancelHttpServiceFiltertohttp-utilsfor 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