gomemcache icon indicating copy to clipboard operation
gomemcache copied to clipboard

Closing client's connection

Open anaktas opened this issue 9 years ago • 7 comments

There isn't any Close() function provided for closing a connection from client side. Probably there is a way to close the connection by manipulating the freeconn attribute of the client instance, but I am not sure if this is a safe solution. Can anyone provide a safe solution for closing a connection from client side?

anaktas avatar Jun 30 '16 10:06 anaktas

and also need some method to destroy whole client..

lysu avatar Aug 09 '16 05:08 lysu

@lysu, I believe that you can destroy the whole client just by nullifying the instance. E.g.:

// Create the memcached client mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212") // Destroy it mc = nil

The GOlang's garbage collector will do all the necessary work for you.

anaktas avatar Aug 09 '16 10:08 anaktas

@anaktas yes...GC will recycle memory and some resource but it's better to close resource by ourself...

for this one, pooled network fd will be added to runtime.SetFinalizer, and close them when gc occur, but the time to close is not predict, it's maybe too late for some situation.. except that... do slow things like "close fd" in finalizer will slower GC..

lysu avatar Aug 12 '16 18:08 lysu

@lysu you have right, I agree with you. You can still use the runtime.GC() to force the GC to run at your demand, but this would have some impact (probably a significant) in the performance of your application.

anaktas avatar Aug 16 '16 09:08 anaktas

Yes, I had the same question. I wonder if @bradfitz has a good solution to do this cleanly.

edasque avatar Jul 19 '17 14:07 edasque

Any update?

mingrammer avatar Apr 08 '20 05:04 mingrammer

I opened this PR, https://github.com/bradfitz/gomemcache/pull/155

renanbastos93 avatar Aug 22 '22 17:08 renanbastos93