Hello,

You should add some mutex locks in there, since it looks like there is some threading try adding some mutex locks and debug_log messages to check for the errros..

Best of luck...