Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 10, 2024

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Jun 7, 2024

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.

public final void operationComplete(ChannelFuture future) throws Exception {

As a result, WriteTimeoutException occurred and tried to reset the
connection.

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

final ChannelFuture f = ch.write(Unpooled.EMPTY_BUFFER);
if (!isWritable(currentId)) {
f.addListener(ChannelFutureListener.CLOSE);
}

Since channel.write() does not respond, the connection cannot be
closed.

Modifications:

  • Rename HttpSession.deactivate() to markUnacquirable() for clarity.
  • Mark the session as unacquirable first before proceeding with the reset
    procedure.
  • Unhealthy connections will be cleaned up eventually with
    KeeyAliveHandler by idle timeout.

Result:

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

…tException` occurs.

Motivation:

I got a report from LINE internally that the connection was not
terminated but hung when the vm instance was shut down due to
maintainance of the underlying hyperviser.

`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 try 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()`. Since `channel.write()` does not respond,
the connection cannot be closed.

Modifications:

- Deactivate `HttpSession` first before proceeding with the reset process.
  - Unhealthy connections will be cleaned up eventually with
    `KeeyAliveHandler` by idle timeout.

Result:

Fixed a bug where a connection was reused after `WriteTimeoutException` occurred.
@ikhoon ikhoon added the defect label Jun 7, 2024
@ikhoon ikhoon added this to the 1.29.0 milestone Jun 7, 2024
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@trustin trustin merged commit f3dbf7b into line:main Jun 10, 2024
15 checks passed
@ikhoon ikhoon deleted the close-connection-on-write-timeout branch June 28, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants