I have come across a very similar problem in my testing and would suggest running your code with strace option to log it to a file. strace shows you all of the system calls your code is making, which is really useful for debugging. Sadly, I have not solved my own issues. Have either you or the other gentleman figured out what was causing the issue?