Copied from T215107#4963154 :
Actionables:
- Database::replaceLostConnection should clean up callbacks before reopening the connection (it's done in handleSessionLoss which is called way too late). Except it also tries to run trxEndCallbacks callbacks (which should survive a rollback) and those need an open connection... so maybe split it in two?
- Also Database::replaceLostConnection should somehow force the open/close logic it calls to ignore trxEndCallbacks and not throw exceptions because of it being set.
- Maybe mark when a connection was closed due to errors and ignore rollback calls in such case? If the connection is lost, the transaction has effectively been rolled back, maybe log a warning but otherwise better to treat it as success than to throw an exception.