Further to my original post, I've been logging the die statements ... I've seen occasionally that the cleanup fails with this error ...
(in cleanup) dbih_getcom handle DBI::db=HASH(0x8388b30) is not a DBI handle (has no magic)
My concern is that this cleanup failure may be wasting resources / memory etc., and eventually kill the server.
Anyone have any views ?
BTW, thanks for the if-block rewrite kesterkester.