Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hack] Restore backtraces in server logs
Summary: For a while now we've been getting useless backtraces in the server logs, e.g. ``` (Sys_error "/tmp/hh_server/hhi_276b1297/hhi_lib__srcs/BuiltinEnum.hhi: Permission denied") Raised at file "format.ml" (inlined), line 239, characters 35-52 Called from file "format.ml", line 465, characters 8-33 Called from file "format.ml", line 480, characters 6-24 ``` The problem comes from here: ``` let with_exit_on_exception f = try f () with | x -> exit_on_exception x ``` The `exit_on_exception` routine does various things, and eventually calls `Hh_logger.exc`, which does various things and then does `Printexc.get_backtrace ()`. The problem is that `Printexc.get_backtrace` merely obtains the most recent contents of the **GLOBAL** "current backtrace" object. Therefore, if any of the "various things" happened to change the global backtrace object (which they did), then the trace printed by Hh_logger.exc will be useless (which it was). In general, the only safe thing to do is to capture the backtrace AT THE MOMENT your 'with' block is invoked. It's not safe to invoke any function before that, unless you can guarantee that their implementations will never modify the global backtrace object. I've changed things around to support this. I made `ServerUtils.with_exit_on_exception` capture the global backtrace as soon as it catches an exception. I've made this bubble all the way down into `Hh_logger.exc`. There are still a load of places which obtain the current global backtrace object in a dodgy way. One of them is from the `Hh_logger.print_with_newline` method (which only has one caller). Several of them used to call `Hh_logger.exc`, which I've renamed to `Hh_logger.exc_with_dodgy_backtrace` to make clear. I didn't do an audit of the rest of the code and don't plan to. Anyway, I've changed just the few places necessary to restore proper backtraces for server exceptions, in a way that's less robust. If we find other poor stacktraces in future, then we can fix those places too. Reviewed By: dabek Differential Revision: D10118184 fbshipit-source-id: 0f5ab9a11c52508c8d1cb9ee675262ae10948bc2
- Loading branch information