GNOME Bugzilla – Bug 752304
[WebDAV book] Generated UIDs can clash with existing
Last modified: 2015-07-14 16:50:22 UTC
Attempting to add a contact to a WebDAV calendar (Radicale server). Getting the following error dialog: Error adding contact: Create resource '643C9869-327B23C6-6B8B4567' failed with HTTP status 412 (Precondition Failed) Watching the HTTP request on the server, there's already a resource with that UID, and thankfully the precondition (If-None-Match: *) prevents the PUT request from overwriting what's already there. Ideas of the cause, without, you know, actually digging into the code, yet: - Not-so-random number generator with bad seed? - Something cached that it's using instead of generating a new UID? Seems pretty easy for me to reproduce.
Alright, did some more testing. The theory that this is a problem with the random number generator is looking pretty strong. I keep trying to save a record, over and over, and it picks other UIDs already in my address book, then finally succeeds because I've gone past UIDs of those already created.
Thanks for a bug report. Just to clean-up a little confusion, you actually do not mean 'calendar', but an 'address book', I believe. I think the pseudo-UUID code can be enhanced, even without depending on any new library for UUID generation. The simplest trick would be to try new UIDs, if the generated one already exists in the book.
I mean address book, yes. Sorry for the confusion. I agree that if it just happened to conflict with an existing UID by chance, that if a 412 is returned, retrying with new UID is a good approach, but I think it's important to properly seed the RNG, otherwise you'll have to iterate through all entries previously created by Evolution before finding an available UID.
Two issues: a) the rand() is very weak, it generates the same sequence for the same seed, while the WebDAV backend didn't seed() at all; b) there was no checking whether the generated UID clashes with any existing, but as for you, it could clash. Current solution: a) use GLib's g_random_int() instead of rand(), which produces better numbers b) check whether generated UID clashes with any existing; if it does, then try again; luckily, it's a cheap operation Created commit 4d4a975 in eds master (3.17.4+) Created commit a26e001 in eds gnome-3-16 (3.16.5+)