Subject: Re: bug#75209: 30.0.93; Emacs reader failed to read data in "/home/nlj/.cache/org-persist/gc-lock.eld"

From: Ihor Radchenko <[email-masked]>
Date: Sat, 15 Mar 2025 16:05:44 +0000

Eli Zaretskii <[email-masked]> writes:

> Hmm... but now I see that the previous code already renamed the file
> with the new data after the new data was completely written, is that
> right?  If so, I don't think this last change will help, and we need
> to understand how come rename-file doesn't already solve this problem.

Yes, it is right.
You suggested using write to temporary file -> rename method earlier and
I implemented it.

> Is the file being read and written a regular file or a symlink?

Regular file.

> One thing to try is to let-bind write-region-inhibit-fsync to a nil
> value around the code which writes the data to the org-persist file.
> Maybe we have some tricky race condition between the filesystem
> flushing its buffer after one instance of Emacs wrote the file, and
> the other instance of Emacs that opens the file for reading.

The attached diff does it. Need to test.

diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index a639699d93..c0a0dd53d6 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -474,7 +474,7 @@ (defun org-persist--write-elisp-file
   ;;
   ;; To read more about this, see the comments in Emacs's fileio.c, in
   ;; particular the large comment block in init_fileio.
-  (let ((write-region-inhibit-fsync t)
+  (let ((write-region-inhibit-fsync nil)
         ;; We set UTF-8 here and in `org-persist--read-elisp-file'
         ;; to avoid the overhead from `find-auto-coding'.
         (coding-system-for-write 'emacs-internal)

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>