You're right. Really, what you want here is per-repository locks. So the first client gets the lock, checks if the image/layers exist and starts the download. The second client ends up waiting for, say, 30 seconds before it can get the lock, but having go it it checks if the image/layers exist and just moves on because they already do. The current poolAdd() conflates the "error" of passing an unknown pool type with the "not really an error, just a status" of saying "hey, this key already exists in this pool, dude".

I'll see what I can do... :-)