Protect download handler against race conditions