It looks like mongodb not shutting down may have been due to a file input handler being opened on the output stream. WIth that removed the problem seems to have disappeared, but this is a hard one to test because it is inconsistent so will keep an eye on it. Added some code to handle logging if we want it in the future.