fix error exit critical section