rust-lang / docs.rs

crates.io documentation generator
https://docs.rs
MIT License
956 stars 193 forks source link

prevent race conditions when initializing crate record in DB #2482

Closed syphar closed 2 months ago

syphar commented 2 months ago

With this I'm trying to prevent this sentry error while building:

error returned from database: duplicate key value violates unique constraint "crates_normalized_name_idx"

I'm not sure yet where this can happen, I saw it once specifically with the crate tencent (which is empty, but this shouldn't matter). Crate name normalization shouldn't change anything for this crate. Also the crate was queued only once in the queue, and SELECT FOR UPDATE should prevent that the second builder would pick up the same release.

In any case, this is the new impl for the method, taken from #2467, which would solve this specific error in all cases.