Skip to content

Await h2 connection releases before closing pool #950

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

Merged
merged 2 commits into from
Dec 14, 2018

Conversation

dagnir
Copy link
Contributor

@dagnir dagnir commented Dec 13, 2018

Description

We must wait for the connection release to be completed (it's an asynchronous
operation) before closing the pool, otherwise it could be left dangling and lead
to a socket leak.

Motivation and Context

Fix socket leak.

Testing

mvn clean install

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@@ -150,6 +164,13 @@ private void releaseParentChannel(Channel parentChannel) {

@Override
public void close() {
connections.forEach(c -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these awaits eventually timeout? Also it may not be a good idea to dispatch the close to the connection pool as it also awaits so that would block a netty thread. I think we can safely move it to the calling thread. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about having a timeout, but what about switching to a normal await() so it's interruptible? +1 moving the close on to the calling thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to the interruptible

@dagnir dagnir force-pushed the transcribe-fix-final branch 2 times, most recently from fae1b0f to 12f8440 Compare December 14, 2018 01:06
@@ -77,6 +92,10 @@
}

private Future<Channel> acquire0(Promise<Channel> promise) {
if (closed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Future improvement, we can make this a decorator to reuse this functionality for HTTP/1.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

@@ -124,6 +143,11 @@ private void releaseParentChannel0(Channel parentChannel, MultiplexedChannelReco
}

private void release0(Channel channel, Promise<Void> promise) {
if (closed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we still let them release after close?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm not sure, I think it's better to error out so the caller can just close the channel if it gets rejected otherwise the other option would be to close it for them here but it seems a little non-obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chatted offline, should be fine to allow release after closing since in reality this would have already been cleaned up by close.

}

private Promise<Void> setClosedFlag() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an advantage to doing it this way versus using an AtomicBoolean or something? Just to let the acquires submitted before close called to get a chance to acquire?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wanted to make sure acquire and close serialized so it's not possible to close while in the middle of an acquire.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, that makes sense.

We must wait for the connection release to be completed (it's an asynchronous
operation) before closing the pool, otherwise it could be left dangling and lead
to a socket leak.
@dagnir dagnir force-pushed the transcribe-fix-final branch from 12f8440 to 44ca0f4 Compare December 14, 2018 01:33
@dagnir dagnir merged commit 1164b4f into aws:master Dec 14, 2018
dagnir added a commit to dagnir/aws-sdk-java-v2 that referenced this pull request Dec 14, 2018
Tests behavior that is not being enforced. Forgot to remove from aws#950
@dagnir dagnir mentioned this pull request Dec 14, 2018
13 tasks
dagnir added a commit that referenced this pull request Dec 14, 2018
Tests behavior that is not being enforced. Forgot to remove from #950
aws-sdk-java-automation added a commit that referenced this pull request Sep 9, 2020
…22c5ac02

Pull request: release <- staging/bb1d5935-f586-4cf7-b8ee-5cd522c5ac02
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.

2 participants