Fix release semaphore when get error.