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.8k stars 912 forks source link

Prevents the connection from being used immediately when `WriteTimeoutException` occurs. #5738

Closed ikhoon closed 3 months ago

ikhoon commented 3 months ago

Motivation:

I got a report from LINE internally where the connection was not terminated but hung when the VM instance was shut down due to maintenance of the underlying hypervisor.

operationComplete() was not called for Channel.write() for this abnormal connection. There was neither a normal response nor a failure response.

https://github.com/line/armeria/blob/f0ec7cb729d1fb33d238c6ea8fb9af41460ab37d/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java#L126-L126 As a result, WriteTimeoutException occurred and tried to reset the connection.

https://github.com/line/armeria/blob/f0ec7cb729d1fb33d238c6ea8fb9af41460ab37d/core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java#L331-L331

failAndReset() calls Channel.write(Unpooled.EMPTY_BUFFER) first and then calls Channel.close().

https://github.com/line/armeria/blob/f0ec7cb729d1fb33d238c6ea8fb9af41460ab37d/core/src/main/java/com/linecorp/armeria/internal/common/Http1ObjectEncoder.java#L371-L374 Since channel.write() does not respond, the connection cannot be closed.

Modifications:

Result:

Fixed a bug where a connection was reused after WriteTimeoutException occurred.

github-actions[bot] commented 3 months ago

🔍 Build Scan® (commit: 8e34185e921ca057c69cd1dc362b89cb14f26ab1)

Job name Status Build Scan®
build-windows-latest-jdk-21 https://ge.armeria.dev/s/e35p2ew6u4chi
build-self-hosted-unsafe-jdk-8 https://ge.armeria.dev/s/ebcup6z3iipyy
build-self-hosted-unsafe-jdk-21-snapshot-blockhound https://ge.armeria.dev/s/kwxvzz5435pgk
build-self-hosted-unsafe-jdk-17-min-java-17-coverage https://ge.armeria.dev/s/y6lhnsslvg2cu
build-self-hosted-unsafe-jdk-17-min-java-11 https://ge.armeria.dev/s/ibdrfbmllpcwq
build-self-hosted-unsafe-jdk-17-leak https://ge.armeria.dev/s/zakho6ovipzwu
build-self-hosted-unsafe-jdk-11 https://ge.armeria.dev/s/qroi27m7prslc
build-macos-12-jdk-21 https://ge.armeria.dev/s/vz4sx6rnboes2