server-mode: Improve shutdown behavior
Add a signalhandler to trigger shutdown and be more paranoid about libuv doing things asynchronously (and about using the full types).
This should fix test cases not shutting down properly.
Please consider this for 3.7.