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

From: "N. Jackson" <[email-masked]>
Date: Thu, 24 Apr 2025 22:15:11 +0000

At 17:24 +0000 on Sunday 2025-04-20, Ihor Radchenko wrote:
>
> "N. Jackson" <[email-masked]> writes:
>
>>> -  (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)
>>
>> I will test this diff and report back.
>
> It has been a while since the last update in this thread.
> Does it mean that the diff fixed the problem for good?

I haven't seen the bug since installing the change quoted above that
let binds `write-region-inhibit-fsync' to nil.

Unfortunately, however, there is a confounding factor because around
the same time as I made this change, I switched from mainly using a
very slow desktop system to using a considerably faster laptop.

A slight tangent follows about the patch to do the atomic write
juggle for Windows systems.

At 12:55 +0000 on Saturday 2025-03-15, Ihor Radchenko wrote:
>
> diff --git a/lisp/org-persist.el b/lisp/org-persist.el
> index a639699d93..202c5e645b 100644
> --- a/lisp/org-persist.el
> +++ b/lisp/org-persist.el
> @@ -506,7 +506,12 @@ (defun org-persist--write-elisp-file
>              (let ((pp-use-max-width nil)) ; Emacs bug#58687
>                (pp data (current-buffer)))
>            (prin1 data (current-buffer))))
> -      (rename-file tmp-file file 'overwrite)
> +      (let ((tmp-file-2 (make-temp-file "org-persist-")))
> +        ;; Just renaming may still not be atomic on Windows, so we do
> +        ;; a bit more complex juggle.
> +        (rename-file file tmp-file-2)
> +        (rename-file tmp-file file)
> +        (delete-file tmp-file-2))
>        (org-persist--display-time
>         (- (float-time) start-time)
>         "Writing to %S" file))))

At 17:43 +0000 on Saturday 2025-03-15, Ihor Radchenko wrote:
>
> `make-temp-name' instead of `make-temp-file'.

After the fix using `make-temp-name' instead of `make-temp-file',
there are still two problems with the code:

Problem 1. `rename-file' produces an error if the file doesn't exist
-- which it doesn't the first time the code runs.

Problem 2. Unlike `make-temp-file', `make-temp-name' requires an
absolute file name otherwise the file ends up in the current
directory, whatever that happens to be at the time of the write.