I would suggest to file a bug report on this.
The best way to report it would be if you can extract the code so far that a single source self contained file shows the issue,
say by providing dummy implementations and values of all the things which are externally used.
Just by looking at the code I did not see why it would be wrong, but that does not mean much.
I probably would try to demo the code version which gets stuck as this can be easily seen as wrong.
Daniel