Catch db environment crashes on shutdown (port from Bitcoin) https://github.com/bitcoin/bitcoin/pull/636