Hack server wedges itself on C assert - use a custom assert that raises ocaml exception
commitd02788839f2fca02b5886e5a35751f3ffee32726
authorAlexander Chow <achow@fb.com>
Thu, 25 Aug 2016 23:37:22 +0000 (25 16:37 -0700)
committerHhvm Bot <hhvm-bot-bot@fb.com>
Thu, 25 Aug 2016 23:45:57 +0000 (25 16:45 -0700)
treec9de1b50481e17c2d1cd22083e8d0a041fd3a126
parenteb799d754ead23f6ec0ea50437345b680f26edcd
Hack server wedges itself on C assert - use a custom assert that raises ocaml exception

Summary:
Hack server wedges itself when a C assert is hit. The server process remains
alive but is no longer checking for client connections being passed down by
the monitor. Also, since the server process is alive, the monitor thinks
everything is normal so doesn't attempt to restart the server.

This was seen in the wild by `assert(hashtbl[slot2].addr == NULL)` in hh_move
failing, causing the server to wedge itself. `hh_client stop` also didn't fix
it since the hung server process isn't accepting the sigusr2 signal either.

C assert is supposed to trigger a sigabrt, which is supposed to terminate
the process. But something here isn't working. I tried installing a sigabrt
signal handler which should catch the sigabrt raised by assert() failure, but
that didn't fix things. I think Ocaml sets up some wonky systems signal
stuff when it flips into C code, but I don't know how to test this preventing
C assert from terminating the program with sigabrt. Normal sigabrt
on the server process works (`kill -6` in a terminal) and the monitor
discovers it as expected. It's just C assert failures that don't.

Fixing this by creating a custom assert macro. I include the file name
and the line number in the failure message, which is preserved in the logs.

Reviewed By: dabek

Differential Revision: D3761344

fbshipit-source-id: 6bacccda06a944e329e58eda01516037622f7e86
hphp/hack/src/heap/hh_shared.c