Add a signal handler to trigger shutdown and be more paranoid about libuv doing things asynchronously. This should fix test cases not shutting down properly.