question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Response<T> is not disposable causing leaked TCP connections.

See original GitHub issue

Describe the bug Response<T> contains a disposable field but is not itself disposable. This is a huge problem because the object indirectly contains a HttpResponseMessage. HttpResponseMessage objects are one of the most important types to dispose because they hold on to TCP connections.

Exception or Stack Trace N/A

To Reproduce Try to put a Response<T> in a using.

Code Snippet https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/src/Response{T}.cs#L14

Expected behavior Response<T> should be disposable so that HttpResponseMessage objects can be properly disposed.

Screenshots N/A

Setup (please complete the following information):

  • OS: all
  • IDE : any
  • 1.0.1

Additional context Add any other context about the problem here.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pakrymcommented, Mar 10, 2020

@AlexandreArpin, you are doing the right thing here. DownloadAsync is one of the few client methods that return “live” network stream that has to be either read to the end or disposed.

0reactions
AlexandreArpincommented, Mar 10, 2020

@pakrym

That’s exactly why we made a decision to keep Response<T> non-disposable and handle complexity in clients instead.

Currently reviewing our dispose patterns and using in our applications since we sometimes have DisposedExceptions.

We have a pretty big throughput of blobs in our applications, does your comment means the Client ensure the response’s stream are correctly disposed?

Currently, we’re doing the following

var response = await blob.DownloadAsync(cancellationToken);
using (response.Value)
{
    return steamDownloader.GetValue(response.Value.Content);
}

Is this not advised?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - TcpClient Memory Leak
I have debugged the code. It adds the connections once and then the if statement stops it being added again. · 1. @Brodie...
Read more >
HTTP outbound endpoint leaking tcp connections
The problem is that the tcp connections are terminated by the external server, but not by Mule which keeps them in the CLOSE_WAIT...
Read more >
You're using HttpClient wrong and it is destabilizing your ...
The using statement is a C# nicity for dealing with disposable objects. Once the using block is complete then the disposable object, ...
Read more >
Are Connection Leaks Causing You Timeouts in SQL ...
There are three scenarios that I have seen cause this error: Connection leaks; Spikes in query response times causing connection pools to fill ......
Read more >
Reactor Netty Reference Guide
How can I debug a memory leak? A.5. How can I debug "Connection prematurely closed BEFORE response"? Appendix B: Observability. B.1.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found