backported fix for handling broken connection for mars cursors