Now closing the channel and the cursor in case of error