missing connection check before returning it

checking if the connection still exists solved lots of random AttributeError exceptions 'NoneType' object has no attribute 'lock'

looking few lines up seems like this check is necessary