syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.67k stars 4.89k forks source link

Multiple copies of spacemacs locking the .cache/recentf #5186

Closed socksy closed 3 years ago

socksy commented 8 years ago

Description

When running multiple copies of emacs, occasionally one editor will lock the .cache/recentf, giving a message like this:

Please type q, s, or p; or ? for help
...emacs.d/.cache/recentf locked by ben@benixos (pid 20848): (s, q, p, ?)? 

Obviously, this is only an issue when running multiple copies of emacs, so probably not a hugely high priority issue.

Reproduction guide

I can't work out which command is being called specifically locking the files, so unfortunately this reproduction is going to be not so helpful:

Expected behaviour: Perhaps this can be solved with the package https://github.com/ffevotte/sync-recentf

System Info

(ansible auto-completion better-defaults c-c   clojure dash emacs-lisp evil-commentary extra-langs elixir git github haskell html javascript latex markdown nixos org php ruby rust spell-checking syntax-checking sql vagrant version-control
         (shell :variables shell-default-height 30 shell-default-position 'bottom))

Backtrace

I've enabled debug-on-error mode now, so I'll update the issue when I next get it so there's an actual backtrace to work from.

StreakyCobra commented 8 years ago

It is probably a consequence of https://github.com/syl20bnr/spacemacs/pull/4281. This probably happen if the two emacs instances try to sync the content of recentf at the same time. Maybe the lock can be removed for this file in some way?

3rd3 commented 8 years ago

I'm experiencing the same problem. :+1:

3rd3 commented 8 years ago

System Info

Unfortunately my configuration does not help very much narrowing down the layers:

 auto-completion
 spell-checking
 syntax-checking
 (ibuffer :variables
          ibuffer-group-buffers-by nil
          )
 (ranger :variables
         ranger-ignored-extensions '(
                                     "mkv" "iso" "mp4" "avi" "mp4" "mkv"
                                     "zip" "rar" "exe" "ps" "webm" "png"
                                     "jpg" "jpeg" "tif" "tiff" "ics" "dmg"
                                     "swf" "gz" "m4a")
         ranger-max-preview-size 4  ;; Megabyte
         ranger-cleanup-eagerly t
         )
 (latex :variables
        latex-enable-auto-fill t)
 org
 git
 github
 version-control
 finance
 extra-langs
 markdown
 emacs-lisp
 haskell
 html
 javascript
 ipython-notebook
 shell-scripts
 java
 (haskell :variables
          haskell-enable-ghc-mod-support nil
          haskell-enable-ghci-ng-support t
          haskell-enable-hindent-style "gibiansky"
          haskell-enable-shm-support nil
          )
 (c-c++ :variables
        c-c++-enable-clang-support t
        )
 gtags
 (python :variables
         python-test-runner 'pytest
         )
 (clojure :variables
          clojure-enable-fancify-symbols t
          )
 (shell :variables
        shell-default-height 20
        shell-default-position 'bottom
        shell-enable-smart-eshell t
        shell-default-shell 'eshell)
 evil-commentary
 )
3rd3 commented 8 years ago

Updating all packages and switching to 0.105.14 solved this for me.

3rd3 commented 8 years ago

The error is back under 0.105.14, reproduction steps unclear.

madhat2r commented 8 years ago

Having this issue as well...

temush commented 8 years ago

+1, the same problem

jupl commented 8 years ago

I'll post details later, but I'm running a single instance of Emacs on Arch Linux and I experience this issue as well.

3rd3 commented 8 years ago

This appears to be a consequence of locks that were established in different network domains, for example at home I'm getting warnings like locked by me@worknetwork and at work it is locked by me@homenetwork.

madhat2r commented 8 years ago

I am on one machine, multiple instances running. Getting this message rather frequently in all of them. So it is not just a different network issue, at least for me.

On Apr 21 at 01:00 PM, 3rd3 notifications@github.com said thus:

[ text/plain ] This appears to be a consequence of locks that were established in different networks, for example at work I'm getting warnings like locked by me@worknetwork and at home it is locked by me@worknetwork.


You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/syl20bnr/spacemacs/issues/5186#issuecomment-213039685

StreakyCobra commented 8 years ago

multiple instances running

@madhat2r :point_up: This is probably the problem. You can try disabling the lockfiles as an alternative: https://github.com/syl20bnr/spacemacs/blob/develop/doc/FAQ.org#why-do-i-get-files-starting-with-

So it is not just a different network issue

jupl and 3rd3 are talking about cases where there is only one instance running, and the different networks may be the problem in these cases.

3rd3 commented 8 years ago

A simple solution might be not to use the network domain name for distinguishing the processes, but just rely on the PID and ignore it if the associated process is terminated.

brabalan commented 8 years ago

I'm consistently having this problem each time I switch from home to work or vice-versa. I also have a single instance running. Is there a solution for this, besides disabling lockfiles?

gmfawcett commented 8 years ago

@brabalan These are untested suggestions. :) You could disable recentf-mode (via Customize); or you could redefine (ask-user-about-lock file other-user) to test whether file is the .recentf file, and if so, always return t (grab the lock on the file) or nil (edit the file even though it is locked). See http://ergoemacs.org/emacs_manual/elisp/File-Locks.html

brabalan commented 8 years ago

@gmfawcett Thank you for the suggestions, I'll give these a try.

Reapor-Yurnero commented 7 years ago

Any solutions now? Still suffered this intensively. This problem occurs every time I close Emacs

gmfawcett commented 7 years ago

@Reapor-Yurnero I've been using the following code. It basically makes the recent-files system stop working, by telling each Emacs instance to write its recent-file information into a separate, process-specific file. So we lose a feature -- but for me, it's been worth not having to deal with the constant lock warnings.

I added the following to my .spacemacs dot file, within the (dotspacemacs/user-config) function:

  (setq recentf-save-file (format "/tmp/recentf.%s" (emacs-pid)))

In the (setq) statement, we specify a unique save-file name for the process. If you're working on Windows, you may need to adjust the format string so that the files are written somewhere other than the /tmp/ directory.

ddxgz commented 7 years ago

Still suffering this problem on Mac when I'm running a single instance of emacs. It occurs every time when I woke up the Mac from sleep. Have tried the method provided by @gmfawcett , but it occurs still.

System Info :computer:

opsxcq commented 6 years ago

Same issue here

elraymond commented 6 years ago

Ran into the same problem, due to my habit of just suspending my PC over night. The "culprit" can be found in .emacs.d/layers/+distributions/spacemacs-base/packages.el:

(defun spacemacs-base/init-recentf ()
  (use-package recentf
    :defer t
    :init
    (progn
      ;; lazy load recentf
      (add-hook 'find-file-hook (lambda () (unless recentf-mode
                                             (recentf-mode)
                                             (recentf-track-opened-file))))
      (setq recentf-save-file (concat spacemacs-cache-directory "recentf")
            recentf-max-saved-items 1000
            recentf-auto-cleanup 'never
            recentf-auto-save-timer (run-with-idle-timer 600 t
                                                         'recentf-save-list)))
    :config
...

Here we see how recentf-mode is unconditionally enabled through a "find-file" hook, which is why it can't be disabled. And we see that recentf-save-list is called every 10 minutes when a timer expires.

So when you suspend over night and resume next morning, the timer of all spacemacs instances has expired and they simultaneously rush to write the recentf file, where they collide due to the emacs file locking mechanism.

I chose to disable that function by means of "around advice", which simply doesn't call the function it "surrounds", namely recentf-save-list. Like this:

 (defun nullify-recentf-save-list (orig-fun &rest args) t)
 (advice-add 'recentf-save-list :around #'nullify-recentf-save-list)

which I put into dotspacemacs/user-config in my dotfile.

Seems to work reasonably well, i.e. the recentf file is never written. Simply because nullify-recentf-save-list just returns true and never calls orig-fun (= recentf-save-list).

Edit:

Or, alternatively, maybe just cancel the timer. This way you still can save the file by calling recentf-save-list manually (or through a bind):

(cancel-timer recentf-auto-save-timer)

That's probably the most simple and minimal invasive way to avoid the race condition talked about above. Of course, changes in the spacemacs layer might break that, whereas the advice approach should work in any case.

For completeness, here also a function that toggles (adds/removes) that advice:

(defun toggle-recentf-save-list-advice ()
  (if (advice-member-p #'nullify-recentf-save-list 'recentf-save-list)
      (advice-remove 'recentf-save-list #'nullify-recentf-save-list)
    (advice-add 'recentf-save-list :around #'nullify-recentf-save-list)))
frankyxhl commented 5 years ago

I have this problem after updating latest Spacemacs's repo.

I choose @elraymond 's

(cancel-timer recentf-auto-save-timer)

and works great!

Thanks for your code!

amiryal commented 5 years ago

Building on the suggestion made earlier by @gmfawcett. My setup uses a different server-name for each Emacs instance, so I added the following to my .spacemacs dot file, within the (dotspacemacs/user-config) function:

(setq recentf-save-file (format "%s.%s" recentf-save-file server-name))

I’ve found that repeated SPC f e R does the correct thing, and does not append superfluous suffixes.

pismute commented 4 years ago

Usually I run new emacs instance for each project. So I figured out my solution. It works somehow. Thanks @amiryal.

    (defvar original-recentf-save-file recentf-save-file)
    (defun change-recentf-save-file-based-on-projectile ()
      "Change recentf-save-file base on project name"
      (let ((new-recentf-save-file (format "%s.%s" original-recentf-save-file (projectile-project-name))))
        (unless (string= recentf-save-file new-recentf-save-file)
          (setq recentf-save-file new-recentf-save-file)

          ; (recentf-cleanup) It doesn't work for me
          ; create new recentf-list with open files
          (setq recentf-list (mapcar 'buffer-file-name (cl-remove-if-not 'buffer-file-name (buffer-list))))

          (recentf-load-list))))

    (add-hook 'projectile-mode-hook #'change-recentf-save-file-based-on-projectile)
    (add-hook 'projectile-after-switch-project-hook #'change-recentf-save-file-based-on-projectile)
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

michael-nhat commented 1 year ago

I still meet the same problem, all spacemacs instance keep asking how I want to process file lock of recentf file. But it happend only with recentf-auto-save-timer (which run function recentf-save-list) , not happend when i run recentf-save-list interactively I write for my self:

(defun nh-recentf-save-list ()
  "docstring"
  (interactive)
  (cl-flet ((ask-user-about-lock (FILE OPPONENT)
                                 (discard-input)
                                 (save-window-excursion (message "nh ask-user-about-lock running")
                                                        '(?p . nil))))
    (message "nh-recentf-save-list working")
    (recentf-save-list)))

(use-package recentf
  :defer (spacemacs/defer)
  :commands (recentf-save-list)
  :init
  (progn
    (spacemacs|require-when-dumping 'recentf)
    (cancel-timer recentf-auto-save-timer)
    (setq
     recentf-auto-save-timer (run-with-idle-timer 1800 t
                                                  'nh-recentf-save-list))
    ))

My solution is temporarily override ask-user-about-lock to make it auto select "process" option, if you want auto select other option, please look into it implementation. Hope this help someone.