Skip to content
This repository

longjmp() in threadpool causes infinite hang on OS X #1362

Open
kkaefer opened this Issue · 3 comments

4 participants

Konstantin Käfer Ben Noordhuis David Dias Trevor Norris
Konstantin Käfer

A C addon that uses setjmp()/longjmp() in a libeio threadpool thread causes child_process.exec to go into an infinite hang. I reduced the test case on https://github.com/kkaefer/child_process_hang. When running node index.js, node won't react to any keyboard input anymore and will stay running infinitely. Only killing with -9 exits it. This seems to only happen on Mac OS X, not on any Linux system I, @yhahn and @bnoordhuis have tested.

Konstantin Käfer kkaefer closed this
Konstantin Käfer kkaefer reopened this
Ben Noordhuis

@kkkaefer, what does this program do when compiled with and without -pthread?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>

static sigjmp_buf env;

static void sigsegv(int signum) {
  (void) signum;
  siglongjmp(env, 1);
}

int main(void) {
  volatile sig_atomic_t n = 0;
  struct sigaction sa;

  memset(&sa, 0, sizeof sa);
  sa.sa_handler = sigsegv;
  sigemptyset(&sa.sa_mask);
  sigaction(SIGSEGV, &sa, NULL);

  if(sigsetjmp(env, 1) && n >= 10) {
    printf("Survived %d segfaults.\n", n);
    return 0;
  }
  else {
    n++;
    *(int *)NULL = 42; /* Force SIGSEGV. */
    return 1;
  }
}
Konstantin Käfer

It works in both cases, with -pthread and without -pthread. It prints "Survived 10 segfaults.", then exits cleanly with status code 0.

David Dias
Collaborator

@kkaefer can you confirm if this is still a thing nowadays? Probably not right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.