fix crash if connection drops unexpectedly