Re-entrant database cleaner

[#56005352]

Keep track if a connection had to be established by
with_established_connection and only remove the connection if one was
established in this call so that nested calls do not remove the
connection of their ancestors.