Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signals and the haskell runtime #3

Open
jeff-davis opened this issue Oct 7, 2022 · 3 comments
Open

Signals and the haskell runtime #3

jeff-davis opened this issue Oct 7, 2022 · 3 comments

Comments

@jeff-davis
Copy link

I haven't looked deeply into this, but on my platform (x86_64 ubuntu 22.04), based on output of strace -p $PID -e signal, it seems that plhaskell makes some changes related to signals due to the haskell runtime.

I see calls to rt_sigaction, rt_sigreturn, and rt_sigprocmask involving SIGVTALRM and SIGURG. It seems that Postgres doesn't use SIGVTARLM, but it does seem to use SIGURG for latches. I'm slightly worried that there are edge cases where a plhaskell function can end up interfering with Postgres.

Is there a way to get the haskell runtime to not mess with the signal handlers?

@ed-o-saurus
Copy link
Owner

ed-o-saurus commented Oct 8, 2022

I turned off signal handlers by passing the RTS the --install-signal-handlers=no option. (see here)

It looks like I should have also added -V0. Does the behavior go away when you add it at line 559 of src/plhaskell.c?

@ed-o-saurus
Copy link
Owner

I ran strace against a postgres backend and was able to observe SIGVALRM calls. How were you able to observe SIGURG calls?

@jeff-davis
Copy link
Author

Without -V0, strace -p $PID -e -signal shows:

rt_sigaction(SIGVTALRM, {sa_handler=0x7ff2c31e2470, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7ff2ce501520}, NULL, 8) = 0
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=2, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 6
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283469926400
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 1
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 2
rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670031, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670032, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670033, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283474141184
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 3
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283473293312
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 0
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 0
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 100
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283469096257
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283468393954
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283468386920
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = -1 ENOENT (No such file or directory)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 283476414856
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 13
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 140680609455626
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 3674937295934324844
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = 0
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = -1 EINTR (Interrupted system call)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = -1 EINTR (Interrupted system call)
--- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_int=0, si_ptr=NULL} ---
rt_sigreturn({mask=[URG]})              = -1 EINTR (Interrupted system call)
...

With -V0, it shows just:

rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670555, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670556, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigprocmask(SIG_BLOCK, [], [URG], 8) = 0
rt_sigprocmask(SIG_SETMASK, [URG], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=670557, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---

The syscalls involving SIGURG are coming from:

#0  __GI___pthread_sigmask (how=0, newmask=<optimized out>, oldmask=0x7f1d54d837e0) at ./nptl/pthread_sigmask.c:43
#1  0x00007f1d6006171d in __GI___sigprocmask (how=<optimized out>, set=<optimized out>, oset=<optimized out>) at ../sysdeps/unix/sysv/linux/sigprocmask.c:25
#2  0x00007f1d4ef577e5 in runInteractiveProcess () from /usr/lib/ghc/process-1.6.9.0/libHSprocess-1.6.9.0-ghc8.8.4.so
#3  0x00007f1d4ef50781 in ?? () from /usr/lib/ghc/process-1.6.9.0/libHSprocess-1.6.9.0-ghc8.8.4.so
#4  0x00000042000c3bc8 in ?? ()
#5  0x00000042000c3be0 in ?? ()
#6  0x00000042000c3bf8 in ?? ()
#7  0x0000000000000000 in ?? ()

This is Postgres v14, PL/Haskell 1.0, Ubuntu 22.04.1 on x86_64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants