Subject: bug#46972: 28.0.50; [feature/native-comp] Emacs locks itself during native compilation because of permission denied

From: Matt M <[email-masked]>
Date: Sat, 6 Mar 2021 17:23:34 +0000

I'm on windows using latest native compilation. I noticed that when doing
doom sync (I use Doom emacs) it would hang on the native compilation
step. I looked at the opened emacs processes in the task manager
during this bug to try to find a file with which I could make the bug
trigger again. In the task manager I see that about 10 emacs processes
are stuck on 10 files.

Using this file: https://pastebin.com/z4wLheXa as
emacs-async-comp-ox-ascii.el, I call the following command:

emacs -Q --batch -l c:/Users/Matt/emacs-async-comp-ox-ascii.el
> Compiling c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/org-mode/ox-ascii.el...

It never finishes. If I interrupt the process I get the following
backtrace:

Debugger entered--Lisp error: (file-error "Removing old name" "Permission denied" "c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c...")
  kill-emacs(t)
  command-line()
  normal-top-level()

Removing old name: Permission denied, c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c6fa13f/ox-ascii-dcca1ba0-825ea35cp6iXUJ.eln.old
Debugger entered--Lisp error: (file-error "Removing old name" "Permission denied" "c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c...")
  command-error-default-function((file-error "Removing old name" "Permission denied" "c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c...") "" debug)
  apply(command-error-default-function ((file-error "Removing old name" "Permission denied" "c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c...") "" debug))
  #f(advice-wrapper :after command-error-default-function help-command-error-confusable-suggestions)((file-error "Removing old name" "Permission denied" "c:/Users/Matt/.emacs.d/.local/cache/eln/28.0.50-4c...") "" debug)

It renamed a file from file.eln to file.eln.old, then tries to delete
the file.eln.old but gets a Permission denied error.

If I start the same command again without interrupting, and try to
delete the file.eln.old manually, I get the error:
Can't remove file because the file is opened in emacs.exe

And the only emacs.exe process runnin on the computer is the one doing
the native compilation, the one which created the file.eln.old.

So that seems to indicate that the emacs process that renames the file
doesn't have the permission to remove the same file because of it being
opened in itself.

In GNU Emacs 28.0.50 (build 1, x86_64-w64-mingw32)
of 2021-03-05 built on DESKTOP-MATT
Repository revision: 552ef6d6c0733b864bcb14eeb6183d7e64df3b80
Repository branch: feature/native-comp
Windowing system distributor 'Microsoft Corp.', version 10.0.19042
System Description: Microsoft Windows 10 Education (v10.0.2009.19042.804)

Configured using:
'configure --with-native-compilation --with-gnutls --with-jpeg
--with-png --with-rsvg --with-xml2 --without-imagemagick --without-pop
--without-dbus'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LIBXML2 MODULES NATIVE_COMP NOTIFY
W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XPM
ZLIB

Important settings:
  value of $LC_CTYPE: fr_FR.UTF-8
  value of $LANG: FRA
  locale-coding-system: utf-8

Major mode: DOOM v2.0.9

Minor modes in effect:
  gcmh-mode: t
  global-hl-line-mode: t
  hl-line-mode: t
  winner-mode: t
  show-paren-mode: t
  ws-butler-global-mode: t
  global-undo-fu-session-mode: t
  undo-fu-session-mode: t
  undo-fu-mode: t
  global-flycheck-mode: t
  smartparens-global-mode: t
  which-key-mode: t
  better-jumper-mode: t
  better-jumper-local-mode: t
  company-box-mode: t
  global-company-mode: t
  company-mode: t
  ivy-prescient-mode: t
  prescient-persist-mode: t
  ivy-rich-project-root-cache-mode: t
  ivy-rich-mode: t
  ivy-mode: t
  evil-goggles-mode: t
  evil-escape-mode: t
  evil-snipe-override-mode: t
  evil-snipe-mode: t
  evil-snipe-override-local-mode: t
  evil-snipe-local-mode: t
  savehist-mode: t
  solaire-global-mode: t
  doom-modeline-mode: t
  key-chord-mode: t
  evil-repeat-motion-mode: t
  global-git-commit-mode: t
  org-roam-mode: t
  persp-mode: t
  shell-dirtrack-mode: t
  evil-mode: t
  evil-local-mode: t
  +popup-mode: t
  general-override-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  window-divider-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/eri/eri hides c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/agda2-mode/eri
c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/annotation/annotation hides c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/agda2-mode/annotation
c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/agda2-mode/agda-input hides c:/Users/Matt/.emacs.d/.local/straight/build-28.0.50/agda-input/agda-input

Features:
(shadow sort whitespace vi-tilde-fringe display-line-numbers
adaptive-wrap gcmh hl-line winner paren ws-butler undo-fu-session
undo-fu flycheck-popup-tip evil-collection-popup popup
evil-collection-flycheck flycheck nav-flash hide-mode-line mail-extr
smartparens-config smartparens-text smartparens emacsbug sendmail
char-fold cursor-sensor amx evil-collection-which-key which-key
better-jumper company-box company-box-doc frame-local company-box-icons
dash-functional company-capf company ivy-prescient prescient
evil-collection-ivy ivy-avy avy all-the-icons-ivy ivy-rich counsel xdg
ivy-xref evil-collection-xref xref project swiper ivy delsel ivy-faces
ivy-overlay colir color evil-goggles pulse evil-easymotion evil-escape
evil-snipe org-agenda lv doom-snippets doom-snippets-lib yasnippet
evil-collection-elisp-mode elisp-mode savehist recentf tree-widget
face-remap persistent-soft list-utils pcache eieio-base font-utils
unicode-fonts doom-themes-ext-org doom-themes-ext-neotree
doom-themes-ext-treemacs solaire-mode doom-one-theme doom-themes
doom-themes-base dtrt-indent doom-modeline doom-modeline-segments
doom-modeline-env doom-modeline-core shrink-path all-the-icons
all-the-icons-faces data-material data-weathericons data-octicons
data-fileicons data-faicons data-alltheicons key-chord
evil-repeat-motion deft orgit evil-collection-magit-todos magit-todos
pcre2el rxt re-builder hl-todo async evil-collection-grep grep
evil-collection-compile compile github-review ghub-graphql treepy gsexp
ghub url-http url-gw nsm url-auth gnutls deferred a
evil-collection-magit magit-autoloads magit-submodule magit-obsolete
magit-popup magit-blame magit-stash magit-reflog magit-bisect magit-push
magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
core-packages package browse-url url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util mailcap
url-handlers magit-repos magit-apply magit-wip magit-log magit-diff
smerge-mode diff git-commit evil-collection-log-edit log-edit message
rmc puny rfc822 mml mml-sec evil-collection-epa epa epg epg-config
gnus-util rmail rmail-loaddefs text-property-search mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums
mail-prsvr mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log
magit-core magit-autorevert autorevert filenotify magit-margin
magit-transient magit-process with-editor evil-collection-term term
ehelp esh-help evil-collection-man man em-unix eshell-z em-dirs esh-var
evil-collection-eshell em-prompt eshell-did-you-mean esh-mode eshell
esh-cmd esh-ext esh-opt esh-proc esh-io esh-arg esh-module esh-groups
esh-util evil-collection-dired dired dired-loaddefs server magit-mode
transient help-mode magit-git magit-section benchmark magit-utils
which-func evil-collection-imenu imenu evil-collection-vc-git vc-git
evil-collection-diff-mode diff-mode ido crm org-roam org-roam-link
org-roam-graph xml org-roam-doctor org-roam-dailies org-roam-capture
org-roam-db emacsql-sqlite3 emacsql emacsql-compiler org-capture
org-roam-completion org-roam-buffer org-roam-faces org-roam-macs
org-roam-compat f s dash org-id org-refile smartparens-org org-yt
org-element avl-tree generator org ob ob-tangle ob-ref ob-lob ob-table
ob-exp org-macro org-footnote org-src ob-comint org-pcomplete org-list
org-faces org-entities time-date noutline outline org-version
ob-emacs-lisp ob-core ob-eval org-table ol org-keys org-compat org-macs
org-loaddefs format-spec find-func evil-collection-calendar
evil-collection-custom cus-edit cus-start cus-load wid-edit
evil-collection-comint evil-collection annalist cal-menu calendar
cal-loaddefs persp-mode let-alist ibuf-macs evil evil-integration
evil-maps evil-commands ffap url-parse auth-source eieio eieio-core
eieio-loaddefs password-cache json map url-vars reveal flyspell ispell
evil-jumps evil-command-window evil-types evil-search shell pcomplete
comint ansi-color evil-macros evil-repeat evil-states evil-core advice
evil-common windmove thingatpt rect evil-digraphs evil-vars ring derived
core-editor core-projects core-ui edmacro kmacro easy-mmode comp
comp-cstr warnings rx core-keybinds pp general cl-extra easymenu seq
byte-opt cl-seq use-package-core bytecomp byte-compile cconv
core-modules realgud-recursive-autoloads cl core core-lib cl-macs gv
cl-loaddefs cl-lib subr-x iso-transl tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook simple abbrev obarray cl-preloaded nadvice button loaddefs
faces cus-face pcase macroexp files window text-properties overlay sha1
md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads w32notify w32 multi-tty
make-network-process nativecomp emacs)

Memory information:
((conses 16 1092168 1889617)
(symbols 48 49260 2178)
(strings 32 164215 99347)
(string-bytes 1 5915413)
(vectors 16 64852)
(vector-slots 8 1222623 822052)
(floats 8 1154 2009)
(intervals 56 811 188)
(buffers 992 13))