Fix crash when trying to use closed connection