Fix crash on sync due to collection being closed