line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.83k stars 922 forks source link

`ClientRequestContext#cancel` cancels the associated request immediately #5800

Closed jrhee17 closed 3 months ago

jrhee17 commented 4 months ago

Motivation:

In order to handle https://github.com/line/armeria/issues/4591, I propose that we first define an API which allows users to cancel a request. Currently, ClientRequestContext#cancel is invoked once CancellationScheduler#start is invoked. I propose to change the behavior of ClientRequestContext#cancel such that the associated request is aborted immediately. Once this API is available, it would be trivial to implement ResponseTimeoutMode by adjusting where to call CancellationScheduler#start. Additionally, users may easily implement their own timeout mechanism if they would like.

Modifications:

Result:

github-actions[bot] commented 4 months ago

🔍 Build Scan® (commit: cc8db8310b7dbe154cf4758d729ec59a29fc1ded)

Job name Status Build Scan®
build-self-hosted-unsafe-jdk-8 https://ge.armeria.dev/s/xt4w6si3fxioe
build-self-hosted-unsafe-jdk-21-snapshot-blockhound https://ge.armeria.dev/s/j463lr36xrngm
build-self-hosted-unsafe-jdk-17-min-java-17-coverage https://ge.armeria.dev/s/z7akszkmjtlio
build-self-hosted-unsafe-jdk-17-min-java-11 https://ge.armeria.dev/s/gk5ifs4ykwdgu
build-self-hosted-unsafe-jdk-17-leak https://ge.armeria.dev/s/jxkgdbss7mqgm
build-self-hosted-unsafe-jdk-11 https://ge.armeria.dev/s/2junq5mszo5ga
build-macos-12-jdk-21 https://ge.armeria.dev/s/ufve7p4hdlpuw
ikhoon commented 3 months ago

https://github.com/line/armeria/pull/5156 has been merged. Would you mind resolving the conflicts?

ikhoon commented 3 months ago

@jrhee17 Would you check the test failures?

ContextCancellationTest > cancel_beforeDelegate(TestInfo) FAILED
    java.lang.AssertionError: 
    Expecting empty but was: [[creqId=147071ed][http://127.0.0.1:34223/#GET]]
        at com.linecorp.armeria.client.ContextCancellationTest.validateCallbackChecks(ContextCancellationTest.java:289)
        at com.linecorp.armeria.client.ContextCancellationTest.cancel_beforeDelegate(ContextCancellationTest.java:115)

ContextCancellationTest > cancel_beforeConnection(TestInfo) FAILED
    java.lang.AssertionError: 
    Expecting empty but was: [[creqId=456bf5ae][http://foo.com:34223/#POST]]
        at com.linecorp.armeria.client.ContextCancellationTest.validateCallbackChecks(ContextCancellationTest.java:289)
        at com.linecorp.armeria.client.ContextCancellationTest.cancel_beforeConnection(ContextCancellationTest.java:153)
jrhee17 commented 3 months ago

Let me go ahead and merge this PR since it's reliable passing the CI again, thanks for the review all 👍