Solve the race condition instead of throwing an exception