libuv / help

Need help with libuv? Post your question here.
28 stars 7 forks source link

How to deal with SIGVTALRM #20

Open winterland1989 opened 7 years ago

winterland1989 commented 7 years ago

First thank you for this great piece of work, my libuv haskell's binding is almost work ; ) Here's a problem, haskell's runtime system will emit SIGVTALRM signal somtime(to achieve timers and to make non-threaded programs don't freeze). When that happed, my libuv program crashes. Is there a way to mask SIGVTALRM with libuv? I read the document and it says UV_LOOP_BLOCK_SIGNAL can only block SIGPROF, is there a way to block SIGVTALRM and SIGALRM(older ghc emit this) too?

Beside the main uv_run call, what about the rest API's behaviour when facing SIGVTALRM / SIGALRM? I'm expecting a errno with UV_EINTR, but maybe i'm wrong.

saghul commented 7 years ago

I guess you could add dummy signal handlers... @bnoordhuis would it make sense to improve uv_loop_configure to be able to block those signals too?

Beside the main uv_run call, what about the rest API's behaviour when facing SIGVTALRM / SIGALRM? I'm expecting a errno with UV_EINTR, but maybe i'm wrong.

EINTR is always handled internally, libuv will never return that error to user code.

winterland1989 commented 7 years ago

I guess you could add dummy signal handlers

I'll give it a try. i don't want to lose compatibility with older version of libuv.

That been said, SIGVTALRM and SIGALRM are pretty like SIGPROF IMO, so i'm pretty happy if you can add them into blocking set in new version.

EINTR is always handled internally, libuv will never return that error to user code.

Does that means they won't be affected by SIGVTALRM and SIGALRM at all?

winterland1989 commented 7 years ago

After i add dummy SIGVTALRM handler, the program will ALWAYS CRASH :cry:

Here's the strace when i start a dummy handler:

clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 10173407}) = 0
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
rt_sigaction(SIGINT, {0x593790, [], SA_RESTORER|SA_RESETHAND|SA_SIGINFO, 0x7f8aedf33390}, NULL, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
futex(0x7f8ad000091c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8ad0000918, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x7f8ad0000948, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x15a74d8, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f8ae000091c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8ae0000918, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
futex(0x7f8ae0000948, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x15d85b8, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x15fa42c, FUTEX_WAIT_PRIVATE, 1, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=0, ptr=0}} ---
read(27, "*", 1)                        = 1
write(31, "\360Y\0\0B\0\0\0\32\0\0\0\0\0\0\0", 16) = 16
write(31, "`[\0\0B\0\0\0\32\0\0\0\0\0\0\0", 16 <ptrace(SYSCALL):No such process>
+++ killed by SIGSEGV (core dumped) +++
bnoordhuis commented 7 years ago

What does the backtrace look like though?

@saghul Yes, that seems fine.

winterland1989 commented 7 years ago

@bnoordhuis Haskell's FFI really didn't provide too much info on the c side stack trace, I'm try to debugging that, it may not be related to SIGVTALRM and SIGALRM.