Prevent race condition when removing connection

fixes #2221