GNOME Bugzilla – Bug 135452
"Failed to lock" -> recent files disappear
Last modified: 2009-08-15 18:40:50 UTC
I'm getting a lot of the following error message on the console. ** (gedit:22996): WARNING **: Failed to lock: Resource temporarily unavailable
This is (was?) due to egg-recent I think it should fixed in the latest gnome 2.5 release. Could you please confirm?
snorp: is this fixed?
Yeah, I haven't seen this in quite some time....
I have! It still quite common for me.
It might be worth noting that most of the editing I do with gedit is on files in a NFS share.
Ah, ok. File locking doesn't always work on NFS. You can (mostly) ignore the message.
So, if the error message can be ignored, maybe it shouldn't be printed?
*** Bug 143821 has been marked as a duplicate of this bug. ***
This still happens on and off in 2.6... From bug 143821: the problem also causes the recent files list to disappear
It is still quite common for me (and I don't use NFS). I have written a simple patch to try to fix this problem, but I cannot fully test it due to a crash bug in my build. snorp: pbor: could you please try to give a look at my patch? I'm not sure about the select (i.e. is it really waiting for a max interval of 1 second? Or is it 10 seconds?) Index: gedit/recent-files/egg-recent-model.c =================================================================== RCS file: /cvs/gnome/gedit/gedit/recent-files/egg-recent-model.c,v retrieving revision 1.13 diff -u -p -r1.13 egg-recent-model.c --- gedit/recent-files/egg-recent-model.c 13 Feb 2004 18:06:26 -0000 1.13 +++ gedit/recent-files/egg-recent-model.c 14 Jul 2004 16:00:36 -0000 @@ -875,27 +875,38 @@ static gboolean egg_recent_model_lock_file (FILE *file) { int fd; - gboolean locked = FALSE; - gint try = 4; + gint try = 5; rewind (file); fd = fileno (file); - /* Attempt to lock the file 4 times, - * waiting 1 second in between attempts. + /* Attempt to lock the file 5 times, + * waiting a random interval (< 1 second) + * in between attempts. * We should really be doing asynchronous * locking, but requires substantially larger * changes. */ - while (try-- > 0) + while (try > 0) { - if ((locked = lockf (fd, F_TLOCK, 0) < 0 ? FALSE : TRUE)); - break; - sleep (1); + int rand_interval; + struct timeval tv; + + if (lockf (fd, F_TLOCK, 0) == 0) + return TRUE; + + rand_interval = 1 + (int) (10.0 * rand()/(RAND_MAX + 1.0)); + + tv.tv_sec = 0; + tv.tv_usec = 100000 * rand_interval; + + select (0, NULL, NULL, NULL, &tv); + + --try; } - return locked; + return FALSE; } static gboolean @@ -906,7 +917,7 @@ egg_recent_model_unlock_file (FILE *file rewind (file); fd = fileno (file); - return lockf (fd, F_ULOCK, 0) < 0 ? FALSE : TRUE; + return (lockf (fd, F_ULOCK, 0) == 0) ? TRUE : FALSE; } static void
This patch looks good to me. I don't get the file locking problem described, so I'm not sure if it really fixes it. Really, we should do asynchronous locking (does that exist?)
ok, thanks. Dummo about asynchronous locking (the commend was in your code :-)
While taking a look at the problem I noticed a behavior which seems fairly reproduceable (it happened 4/4) 1) open a file in gedit -> recent files list is ok 2) make some modification and save -> recent files list disappear If the bug is triggered by the file write, it would explain why eog and gpdf (which only read the files) do not suffer this problem
pbor: it seems to work well with my local patch. Could you please test it and try to reproduce it? I'm attaching a new version of my patch using g_usleep instead of select. Index: gedit/recent-files/egg-recent-model.c =================================================================== RCS file: /cvs/gnome/gedit/gedit/recent-files/egg-recent-model.c,v retrieving revision 1.13 diff -u -p -r1.13 egg-recent-model.c --- gedit/recent-files/egg-recent-model.c 13 Feb 2004 18:06:26 -0000 1.13 +++ gedit/recent-files/egg-recent-model.c 19 Jul 2004 15:08:35 -0000 @@ -875,27 +875,34 @@ static gboolean egg_recent_model_lock_file (FILE *file) { int fd; - gboolean locked = FALSE; - gint try = 4; + gint try = 5; rewind (file); fd = fileno (file); - /* Attempt to lock the file 4 times, - * waiting 1 second in between attempts. + /* Attempt to lock the file 5 times, + * waiting a random interval (< 1 second) + * in between attempts. * We should really be doing asynchronous * locking, but requires substantially larger * changes. */ - while (try-- > 0) + while (try > 0) { - if ((locked = lockf (fd, F_TLOCK, 0) < 0 ? FALSE : TRUE)); - break; - sleep (1); + int rand_interval; + + if (lockf (fd, F_TLOCK, 0) == 0) + return TRUE; + + rand_interval = 1 + (int) (10.0 * rand()/(RAND_MAX + 1.0)); + + g_usleep (100000 * rand_interval); + + --try; } - return locked; + return FALSE; } static gboolean @@ -906,7 +913,7 @@ egg_recent_model_unlock_file (FILE *file rewind (file); fd = fileno (file); - return lockf (fd, F_ULOCK, 0) < 0 ? FALSE : TRUE; + return (lockf (fd, F_ULOCK, 0) == 0) ? TRUE : FALSE; } static void
With this patch I cannot trigger it anymore and the patch makes sense on its own. This is good. Nontheless I am wondering if someone with knowledge of recent-files code could make sense of the info which relates this bug to the saving operation (see my last comment), provided that someone else manage to reproduce it following my instructions. Since the patch seems unrelated, I fear that maybe we are just papering over the bug.
Ok, I'm going to commit the patch. snorp: do you think it should be committed to libegg too?
Yeah, it looks good. Please commit to libegg :)
Committed to libegg too.