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

TcpClient/Socket objects disposed but still exist in memory #263

Closed
sungam3r opened this issue Oct 10, 2016 · 10 comments
Closed

TcpClient/Socket objects disposed but still exist in memory #263

sungam3r opened this issue Oct 10, 2016 · 10 comments
Assignees
Milestone

Comments

@sungam3r
Copy link
Contributor

Memory dump of our running app shows something like this:

11

Both TcpClient and Socket objects have already been disposed, but still in memory referenced by TcpClientAdapter. TcpClientAdapter has private TcpClient / Socket field (depends of rabbitmq-dotnet-client version) which closed (disposed) in TcpClientAdapter.Close() method. We can consider this situation as memory leak with non-growing memory overhead.

12

It's annoying to have those broken and unused objects (with all inner object trees, e.g. byte arrays or ManualResetEvents) in memory and in profiler reports. These objects prevent from investigation real memory leaks.

Please, consider to break reference to TcpClient / Socket in TcpClientAdapter after Close() call.
Maybe, it's better to break reference a bit higher in call stack, e.g. SocketFrameHandler class.

@kjnilsson
Copy link
Contributor

We can certainly null the socket field in the Close method of TcpClientAdapter. What is the scenario where you are holding onto the Connection object after it has been closed?

@kjnilsson kjnilsson self-assigned this Oct 10, 2016
@sungam3r
Copy link
Contributor Author

We use EasyNetQ library and just call RabbitHutch.CreateBus and then Publish / Subscribe methods. App uses 6 RabbitAdvancedBus instances at the same time, serving 6 rpc-request and around 20-40 rpc-response queues.

@sungam3r
Copy link
Contributor Author

Why do you think that the Connection object has been closed?

@kjnilsson
Copy link
Contributor

If the socket and TcpClientAdaptor have already been disposed why keep the Connection instance around? IIRC EasyNetQ doesn't use the AutorecoveringConnection so not sure what the scenario is where the socket has been disposed but the Connection is still somehow in use.

@sungam3r
Copy link
Contributor Author

Indeed, connection is closed (m_closed = true). But EasyNetQ really holds reference to Model object, which in turn holds reference to closed Connection.

@sungam3r
Copy link
Contributor Author

13

@kjnilsson
Copy link
Contributor

May be worth getting onto the EasyNetQ maintainers and ask them to clean up after connection close.

@sungam3r
Copy link
Contributor Author

May be, but it is good practice to break clearly known references to dead objects trees in own code. It protects from improper external use (as EasyNetQ does) and reduces memory footprint.

@michaelklishin
Copy link
Member

We can do both ;)

On 11 Oct 2016, at 17:22, Ivan Maximov notifications@github.com wrote:

May be, but it is good practice to break clearly known references to dead objects trees in own code. It protects from improper external use (as EasyNetQ does) and reduces memory footprint.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@sungam3r
Copy link
Contributor Author

Thank you! I will continue to investigate improper memory usage in EasyNetQ code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants