Two of the threads in the native code are killed via I/O to a native file descriptor during the close method. One or both of these threads does other things that make it not close immediately after the native file descriptor write returns. I'm pretty sure that's the issue. (I'm also putting this paraphrased into a comment in the code)