It appears that when sleep or nanosleep return to a thread through a
scheduler activation the return path doesn't set signotify, so the
sleep termination isn't delivered to the process containing the
sleeping thread until signotify happens to be set for some other
reason.
Below is a diff that fixes the symptom, but I'm not sure whether or
not it's a band-aid or solves the underlying problem.
diff src/sys/kern/kern_time.c.old src/sys/kern/kern_time.c
@@ -1470,6 +1470,7 @@
} else if (pt->pt_ev.sigev_notify == SIGEV_SA && (p->p_flag & P_SA)) {
/* Cause the process to generate an upcall when it returns. */
+ signotify(p);
if (p->p_userret == NULL) {
/*
* XXX stop signals can be processed inside tsleep,