I am also a little concerned by the “forever” loop within the
ContextManager.cleanupOnError.
I wish I could give you more help.
About all I can say is: that is some old, old code, and I don't
recall it being a problem.
That doesn't mean it has no bugs, but I definitely don't know of any.
That being said, going to the Derby JIRA
https://issues.apache.org/jira/browse/DERBY
and doing a search for "derby contextmanager" shows some interesting
old issues, such as DERBY-1947:
https://issues.apache.org/jira/browse/DERBY-1947
So you might want to spend some time looking through a few of those
old jobs for some possible clues.
bryan