unit: Segfault on ctrl-c?
Hey guys,
This is a a relatively small issue (it doesn’t affect running Unit), and more of an annoyance than anything else. But when I start Unit up:
root@5c3fab7a5f96:/# unitd --user root --log /dev/stderr --tmp /tmp --no-daemon
2021/06/24 21:00:28 [info] 9277#9277 unit started
2021/06/24 21:00:28 [info] 9278#9278 discovery started
2021/06/24 21:00:28 [notice] 9278#9278 module: ruby 2.7.3 "/usr/local/modules/ruby.unit.so"
2021/06/24 21:00:28 [info] 9277#9277 controller started
2021/06/24 21:00:28 [notice] 9277#9277 process 9278 exited with code 0
2021/06/24 21:00:28 [info] 9281#9281 "app" application started
And then hit ctrl-c, I always get a segfault:
^C2021/06/24 21:00:42 [warn] 9281#9282 [unit] Ruby: UBF
2021/06/24 21:00:42 [alert] 9277#9277 sendmsg(12, -1, -1, 1) failed (32: Broken pipe)
2021/06/24 21:00:42 [alert] 9277#9277 sendmsg(13, -1, -1, 1) failed (32: Broken pipe)
NGINX_Unit: [BUG] Segmentation fault at 0x0000000000000018
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0003 E:002140 (none) [FINISH]
-- Machine register context ------------------------------------------------
RIP: 0x00007f3e560afba1 RBP: 0x0000000000000008 RSP: 0x00007ffdef260d20
RAX: 0x0000000000000000 RBX: 0x00007f3e4578b858 RCX: 0x00007f3e5746b2d0
RDX: 0x0000000000000001 RDI: 0x0000000000000000 RSI: 0x0000000000000006
R8: 0x00007f3e452ae380 R9: 0x0000000000000004 R10: 0x0000000000000000
R11: 0x00007f3e574009c0 R12: 0x00007f3e5746b2d0 R13: 0x0000000000000006
R14: 0x00007f3e565aa828 R15: 0x0000000000000000 EFL: 0x0000000000010202
-- C level backtrace information -------------------------------------------
2021/06/24 21:00:42 [notice] 9277#9277 process 9279 exited with code 0
2021/06/24 21:00:42 [notice] 9277#9277 process 9280 exited with code 0
/usr/local/lib/libruby.so.2.7(rb_vm_bugreport+0x7ce) [0x7f3e5628851e] vm_dump.c:755
/usr/local/lib/libruby.so.2.7(rb_bug_for_fatal_signal+0xe7) [0x7f3e560a7df7] error.c:660
/usr/local/lib/libruby.so.2.7(sigsegv+0x4b) [0x7f3e561ec3ab] signal.c:946
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7f3e58580980]
/usr/local/lib/libruby.so.2.7(rb_ec_tag_jump+0x1) [0x7f3e560afba1] eval_intern.h:171
/usr/local/lib/libruby.so.2.7(rb_longjmp+0xc6) [0x7f3e560b07a6] eval.c:655
/usr/local/lib/libruby.so.2.7(rb_exc_raise+0x2c) [0x7f3e560b175c] eval.c:673
/usr/local/lib/libruby.so.2.7(rb_interrupt+0x1f) [0x7f3e560b1adf] eval.c:699
/usr/local/lib/libruby.so.2.7(rb_signal_exec+0x74) [0x7f3e561ed824] signal.c:1090
/usr/local/lib/libruby.so.2.7(rb_threadptr_execute_interrupts+0x40a) [0x7f3e5622f7ca] thread.c:2225
/usr/local/lib/libruby.so.2.7(rb_nogvl+0x1fa) [0x7f3e5623104a] thread.c:1478
/usr/local/modules/ruby.unit.so(nxt_ruby_start+0x501) [0x7f3e565b83b5] src/ruby/nxt_ruby.c:277
/usr/local/sbin/unitd(nxt_process_created_ok+0x32) [0x555833a0f208] src/nxt_process.c:348
/usr/local/sbin/unitd(nxt_port_rpc_handler+0xae) [0x555833a1271f] src/nxt_port_rpc.c:347
/usr/local/sbin/unitd(nxt_port_handler+0x22) [0x555833a12c08] src/nxt_port.c:181
/usr/local/sbin/unitd(nxt_port_read_msg_process+0x7b) [0x555833a0f9e3] src/nxt_port_socket.c:1228
/usr/local/sbin/unitd(nxt_port_read_handler+0x9d) [0x555833a0fe9b] src/nxt_port_socket.c:741
/usr/local/sbin/unitd(nxt_event_engine_start+0x143) [0x555833a190dd] src/nxt_event_engine.c:542
/usr/local/sbin/unitd(main+0x6d) [0x555833a0d867] src/nxt_main.c:35
Not sure what’s causing this exactly but it would be nice to see Unit gracefully quit.
Thanks!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 29 (19 by maintainers)
Commits related to this issue
- Ruby: fixed segfault on SIGTERM signal. This closes #562 issue on GitHub. — committed to nginx/unit by hongzhidao 2 years ago
- Ruby: prevented a segfault on receiving SIGINT (^C). As was reported[0] by @travisbell on GitHub, if running unit from the terminal in the foreground when hitting ^C to exit it, the ruby application ... — committed to ac000/unit by ac000 2 years ago
@travisbell
Thanks for testing!
I did test that and it seems things are happening in the right order so that you are able to trap SIGINT in your app and it will override the ignoring of SIGINT by the ruby application process.
In other words, with the above patch I tested the below ruby script
and got the message (and no crash…)
Hey @ac000,
Thanks for the seemingly simple solution. I gave this change a try and while it does seem to prevent the segfault, I do have a question, would this change prevent us from rescuing
SIGINTin the app?Hi @travisbell - sorry for my late response. This will be part of the next release. @hongzhidao fyi.