After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752304 - [WebDAV book] Generated UIDs can clash with existing
[WebDAV book] Generated UIDs can clash with existing
Status: RESOLVED FIXED
Product: evolution-data-server
Classification: Platform
Component: Contacts
3.16.x (obsolete)
Other Linux
: Normal normal
: ---
Assigned To: evolution-addressbook-maintainers
Evolution QA team
Depends on:
Blocks:
 
 
Reported: 2015-07-13 05:39 UTC by Paul Bryan
Modified: 2015-07-14 16:50 UTC
See Also:
GNOME target: ---
GNOME version: 3.15/3.16



Description Paul Bryan 2015-07-13 05:39:40 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.
Comment 1 Paul Bryan 2015-07-14 07:28:34 UTC
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.
Comment 2 Milan Crha 2015-07-14 16:05:31 UTC
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.
Comment 3 Paul Bryan 2015-07-14 16:43:18 UTC
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.
Comment 4 Milan Crha 2015-07-14 16:50:22 UTC
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+)