-
Notifications
You must be signed in to change notification settings - Fork 586
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
Web.Deliver[Async] not Disposing connections #118
Comments
Thank you! I'll get this sorted out soon. |
The general consensus I've found is that connections are automatically reused and therefore explicitly disposing them hinders performance rather than helps it. From Darrel Miller's blog:
And from Henrik Nielsen, one of the principal engineers of HttpClient:
What am I missing here? |
I now think the cause of degraded performance during concurrent calls might be a result of the default connection limit specified by ServicePoint: https://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit.aspx That limit appears to be dependent on environment in some instances. This might be causing the connection pool to lock. |
"You should try and re-use your HttpClient instances" You are clearly not doing this. That would require pooling of some sort. You instantiate the HttpClient and then you let it fall out of scope. But The whole IDisposable pattern is basically there to represent the fact that I had to patch our production servers with a change and the Dispose() I know about the configuration setting, we already have this set in our
|
Your solution does not re-use the connection either, is closing the connection every time. I don't doubt that it works but I want to leave the connection open and re-use it, not dispose of it after each request. You say "that would require pooling of some sort." But each instance of HttpClient has an implicit pool:
I will work on defining the client outside of the scope of the deliver() call and re-using it, but I will not dispose the object explicity. |
Thanks for your help with this. The next nuget release (code is in master) will reuse the connection. |
This bug still exists in the latest version of the code. On this line the On top of this, the So a |
As a note the |
I will fix the interface implementations, but I have clearly stated that I will not dispose the |
From that very answer:
However, you're not doing this. You keep creating new ones every time someone instantiates the Further down in the comments:
Again, you are not re-using the instance. If I have 25 threads and they all create an instance of
The StackOverflow answer you point to is very nuanced. They're not arguing that you should never Dispose of the But the current code is doing neither. It's not re-using the |
Wait. This code creates -- but does not explicitly reuse -- Note to self: Don't try to use SendGrid from .Net. |
Thanks to all for putting in their comments and suggestions! I'm not sure when we'll have time to dig in, but we will as soon as we can. Any additional advice on how to proceed is much appreciated, since .NET/C# is not my primary platform (I already see some good pointers, thanks!). A pull request would even be more awesome ;) |
I just committed an improvement in my fork to address this issue. See PR #211. The improvement is twofold:
|
Nice work @Jericho! |
Updating travis and setup.py for specific python version compatibility
Both the
Deliver
andDeliverAsync
methods declare anHttpClient
but do not leverage ausing()
block of have any code to actively close the connection. This leaves the connection hanging..NET limits the number of connections to a given outbound server, so with no clean-up it effectively render SendGrid "unresponsive" from that server.
This is likely the cause of issue #93.
The text was updated successfully, but these errors were encountered: