Repository navigation
Closed
Description
There has been some investigation over the years about this, but it was never really resolved. @oknet put some asserts in the code to crash when the NetHandler has been acquired but not released, and we bumped into it this week.
It's hard for me to give a working example to reproduce because it's very coupled with a lot of other code, but I'll explain what the code does, so hopefully someone has an idea to solve it.
- We have a plugin with session hooks, TS_EVENT_HTTP_SSN_START and TS_EVENT_HTTP_SSN_CLOSE.
- On SSN_START, the plugin sends a request to
https://localhost, which is the TrafficServer service itself, which then proxies to a Google Compute Storage bucket. We do this because we want to cache the response from GCS in the same node that sends the request. When we receive the response, we save the object in the session withTSHttpSsnArgSetso we can reuse it in other hooks withTSHttpSsnArgGet - On SSN_CLOSE, we do two things, remove the object from the session, with
TSHttpSsnArgSet, and then reenable the session withTSHttpSsnReenable(session, TS_EVENT_HTTP_CONTINUE);. The crash happens when the session releases resources after it's reenabled.
As I mention in the title, this only happens with http/1 because http/2 doesn't have any of the same keepalive logic. It's very easy to reproduce with curl --http1.1 when "you have the whole system working" 😆
[Oct 3 19:19:35.072] [ET_NET 11] DIAG: (netlify_resolve_async) Resolving bundle... host=traffic-mesh-test.netlify.com
Fatal: UnixNetVConnection.cc:1449: failed assertion `!"BUG: It must have acquired the NetHandler's lock before doing anything on keep_alive_queue."`
traffic_server: received signal 6 (Aborted)
traffic_server - STACK TRACE:
bin/traffic_server(_Z19crash_logger_invokeiP9siginfo_tPv+0xa8)[0x555d66264578]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0)[0x7f4e5f2783c0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb)[0x7f4e5ed6418b]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x12b)[0x7f4e5ed43859]
/opt/ts/lib/libtscore.so.9(+0x60cc1)[0x7f4e5f77fcc1]
/opt/ts/lib/libtscore.so.9(+0x5e01b)[0x7f4e5f77d01b]
bin/traffic_server(_ZN18UnixNetVConnection23add_to_keep_alive_queueEv+0x125)[0x555d66506525]
bin/traffic_server(_ZN18Http1ClientSession7releaseEP16ProxyTransaction+0x144)[0x555d662c91a4]
bin/traffic_server(_ZN12ProxySession17handle_api_returnEi+0xbe)[0x555d664b0d9e]
bin/traffic_server(_ZN12ProxySession17state_api_calloutEiPv+0x52)[0x555d664b0e12]
bin/traffic_server(_ZN17TSHttpSsnCallback13event_handlerEiPv+0x6e)[0x555d66293c7e]
bin/traffic_server(_ZN7EThread13process_eventEP5Eventi+0x34d)[0x555d6654f21d]
bin/traffic_server(_ZN7EThread13process_queueEP5QueueI5EventNS1_9Link_linkEEPiS5_+0x24e)[0x555d6654f94e]
bin/traffic_server(_ZN7EThread15execute_regularEv+0x186)[0x555d6654fdf6]
bin/traffic_server(_ZN7EThread7executeEv+0x1ee)[0x555d6655054e]
bin/traffic_server(+0x3e88a9)[0x555d6654e8a9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9609)[0x7f4e5f26c609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f4e5ee40293]
Activity
calavera commentedon Oct 8, 2020
It might also be worth mentioning that we don't use the Fetch apis that TrafficServer provides to send that request, because we want to use an H/2 client for better performance fetching those objects from GCS, so the call is not considered internal from TrafficServer's point of view.
[-]Deadlock in UnxNetVConnection with 9.0.x and http 1[/-][+]Deadlock in UnixNetVConnection with 9.0.x and http 1[/+]shinrich commentedon Oct 8, 2020
Does this happen fairly reliably when a SSN_CLOSE hook is used? What is the event value that is being passed up the callstack? Generally this is a net I/O event, so the nethandler is already locked. However in this case, the item at the bottom of the stack does not appear to be a net I/O event. Probably a reschedule. (event 1 or 2).
calavera commentedon Oct 12, 2020
I was wrong, it looks like it happens during SSN_START, after the hook is triggered. The event is a TS_EVENT_HTTP_CONTINUE triggered with TSHttpSsnReenable.
I changed our plugin to not go through trafficserver for that http request, going directly to the origin and not caching anything. It still fails in the same way, so that's not what's causing the problem.
I got this stacktrace in gdb:
These are some more logs that I captured with my debug version:
shinrich commentedon Oct 23, 2020
So TSHttpSsnReenable, will do a schedule_imm (which results in event 1) with TSHttpSsnReenable as the target continuation if it fails to get the session mutex. Or if the reenable is called from a non ET_NET thread. I'm guessing that is the case that is triggering for your plugin. I doubt there would be lock contention on the session.
So that is not coming up through the net I/O event handling, so the nethandler lock is not being held before the add_to_keep_alive_queue() is called.
Let me ponder how/where to add the nethandler lock in this case.
shinrich commentedon Oct 23, 2020
I have a solution. Will put up a PR shortly for you to try @calavera. I want to add an autest as well to catch the regression.