summaryrefslogtreecommitdiff
path: root/proxy_config.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-11-22 19:27:28 -0800
committerdormando <dormando@rydia.net>2022-12-12 16:07:09 -0800
commitd401611ba88db17c38fedf97d336f8085ce24bab (patch)
tree92ab4f8e947a59eb12bf7a87219667fb5c054116 /proxy_config.c
parent3cbd069ed883d1405c068d0bc104a2a0b2ebeecb (diff)
downloadmemcached-d401611ba88db17c38fedf97d336f8085ce24bab.tar.gz
proxy: fix lifecycle of backend connections
A backend's connection object is technically owned by the IO thread after it has been created. An error in how this was done lead to invalid backends being infinitely retried despite the underlying object being collected. This change adds an extra indirection to backend objects: a backend_wrap object, which just turns the backend connection into an arbitrary pointer instead of lua memory owned by the config VM. - When backend connections are created, this pointer is shipped to the IO thread to have its connection instantiated. - When the wrap object is garbage collected (ie; no longer referenced by any pool object), the be conn. pointer is again shipped to the IO thread, which then removes any pending events, closes the sock, and frees data.
Diffstat (limited to 'proxy_config.c')
-rw-r--r--proxy_config.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/proxy_config.c b/proxy_config.c
index 47414fa..6bb54be 100644
--- a/proxy_config.c
+++ b/proxy_config.c
@@ -78,6 +78,11 @@ static void *_proxy_manager_thread(void *arg) {
luaL_unref(L, LUA_REGISTRYINDEX, p->self_ref);
}
pthread_mutex_unlock(&ctx->config_lock);
+ // force lua garbage collection so any resources close out quickly.
+ lua_gc(L, LUA_GCCOLLECT);
+ // twice because objects with garbage collector handlers are only
+ // marked on the first collection cycle.
+ lua_gc(L, LUA_GCCOLLECT);
// done.
pthread_mutex_lock(&ctx->manager_lock);