Skip to content

Add more tests to verify connection closure and small code clean up #1034

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 1 commit into from
Jan 29, 2019

Conversation

zoewangg
Copy link
Contributor

Description

Reviewed all use of connection closure and verified the resources are being properly released/closed/shutdown after each request as well as after invoke client#close.

This PR added more tests to verify the correctness and did some small code cleanup.

Summary of Connection Closure

Per Request

  • Sync path:

Sockets are being closed by closing the underlying InputStream via HandleResponseStage#closeInputStreamIfNeeded unless needsConnectionLeftOpen is true (default to false).

For streaming requests, if a customized ResponseHandler is provided with needsConnectionLeftOpen overriden to true, the underlying connection will not be closed.

  • Async path:

Channels are being released after each request in netty module unless keep alive is true via ResponseHandler#finalizeRequest (I renamed it to finalizeResponse in this PR)

Per Client After invoking Client#close

  • SDK

    • the thread pools will be shutdown and all Closable will be closed via AmazonSyncHttpClient#close and AmazonAsyncHttpClient#close
    • the underlying http client will be closed unless it's a customer provided client.
  • ApacheHttpClient:
    HttpClientConnectionManager will be shutdown and IdleConnectionReaper will be cleaned up.

  • NettyNioAyncHttpClient
    EventLoopGroup will be shutdown and channel pools will be closed

  • UrlConnectionHttpClient
    No op. Nothing to close

Let me know if I missed anything.

License

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

@zoewangg zoewangg requested a review from dagnir January 24, 2019 00:07
@codecov-io
Copy link

codecov-io commented Jan 24, 2019

Codecov Report

Merging #1034 into master will increase coverage by 0.07%.
The diff coverage is 89.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1034      +/-   ##
============================================
+ Coverage     55.57%   55.65%   +0.07%     
- Complexity     4590     4598       +8     
============================================
  Files           815      815              
  Lines         27906    27918      +12     
  Branches       2246     2246              
============================================
+ Hits          15509    15538      +29     
+ Misses        11676    11658      -18     
- Partials        721      722       +1
Impacted Files Coverage Δ Complexity Δ
.../http/apache/internal/ApacheHttpRequestConfig.java 96.42% <ø> (ø) 7 <0> (ø) ⬇️
...dk/http/urlconnection/UrlConnectionHttpClient.java 81.25% <ø> (ø) 10 <0> (ø) ⬇️
...rnal/http/pipeline/stages/HandleResponseStage.java 80.48% <ø> (ø) 11 <0> (ø) ⬇️
...awssdk/http/nio/netty/NettyNioAsyncHttpClient.java 66.36% <100%> (+2.28%) 17 <2> (+1) ⬆️
...wssdk/http/nio/netty/internal/ResponseHandler.java 62.83% <100%> (ø) 13 <0> (ø) ⬇️
...re/amazon/awssdk/http/apache/ApacheHttpClient.java 62.42% <100%> (+3.67%) 18 <0> (+1) ⬆️
...ttp/pipeline/stages/MakeAsyncHttpRequestStage.java 79.16% <33.33%> (ø) 16 <0> (ø) ⬇️
...are/amazon/awssdk/core/internal/util/Mimetype.java 78.04% <0%> (-2.44%) 14% <0%> (-1%)
...rnal/http/pipeline/stages/AsyncRetryableStage.java 85.5% <0%> (+2.89%) 3% <0%> (ø) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89826f1...980b09d. Read the comment docs.


@Override
public void close() {
isClosed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: any reason not to call super.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.

Per javadoc, ByteArrayInputStream#close has no effect.

Closing a {@code ByteArrayInputStream} has no effect.

client.streamingOutputOperation(b -> b.build(), new ResponseTransformer<StreamingOutputOperationResponse, Object>() {

@Override
public Object transform(StreamingOutputOperationResponse response, AbortableInputStream inputStream) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about adding a similar test where we return the inputStream, and then call close() and then check to see that the wrapped InputStream is closed?

We could look into a similar test for async

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, will add that test.

I thought about adding a similar test for async but unlike sync where connections are being closed by closing the inputStream, channels are being released in the netty module so there's no easy way to verify that here.

@zoewangg zoewangg force-pushed the zoewang-connectionClosureTests branch from 7e1ca53 to 980b09d Compare January 29, 2019 18:12
@zoewangg zoewangg merged commit f68a0eb into master Jan 29, 2019
@zoewangg zoewangg deleted the zoewang-connectionClosureTests branch January 29, 2019 18:51
aws-sdk-java-automation pushed a commit that referenced this pull request Nov 9, 2020
…69f3a15f9

Pull request: release <- staging/750488da-2bcf-4605-aef6-f0669f3a15f9
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.

3 participants