I've made progress on this. The short version is that there seems to be some interaction between resty.string and the Lua code cache that causes the corruption. I can make the assertion failures disappear if I leave the Lua code cache "on" (the default) instead of including "lua_code_cache off" in the nginx conf (as I've been doing during development).
I have a small configuration that reliably provokes a GC assertion failure on server shutdown on my RHEL 6 system using openresty 1.2.8.5.
Use this nginx.conf:
--------------------------------------------------
worker_processes 1;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
lua_code_cache off;
server {
listen 15080 default_server;
location / {
rewrite_by_lua 'require "resty.string"';
content_by_lua 'ngx.say("Hello")';
}
}
}
--------------------------------------------------
Then send the server two requests in succession, e.g.:
$ curl -s -D - http://localhost:15080/x
$ curl -s -D - http://localhost:15080/x
Then shut down the server, e.g.
$ /usr/local/openresty/nginx/sbin/nginx -s stop
This provokes a GC assertion failure in error.log:
lj_state.c:169: close_state: Assertion `g->gc.total == sizeof(GG_State)' failed.
If the "lua_code_cache off" line is commented out in nginx.conf, the assertion failure doesn't happen.
I hope this is helpful.