Subject: 28.2; Forbidden reentrant call of Tramp

From: Georgi Danov <[email-masked]>
Date: Tue, 3 Jan 2023 21:52:36 +0100

As discussed in github issue
https://github.com/joaotavora/eglot/issues/859# eglot over tramp throws
"reentrant call" error. This is sympthom of underlying design issue -
 aux libraries use files without being aware of the tramp conection, the
 connection itself has no concurrency control, pooling or other
 multi-user features and without that guard error different tramp clients
 corrupt each other's communication with the language server.

The problem is reproducible by using company mode, probably the language
is not important. In my case it's typescript. Takes 15-30 seconds of
editing and autocomplete to trigger it.

The main congestions seems to happen in file-truename() -- after
displaying candidate company mode goes on to do refresh in the background
and calls file-truename repeatedly while eglot (or someone else) is occupying the tramp
connection. Point is -- the same tramp connection is used by eglot and
any other minor mode that queries file name or state, but they have no
means to share or coordinate this use other than the exception above.

Tramp used to throw more insignificant error in the past and tolerate
the behavior (which corrupts the data exchanged between eglot and the
lsp) and now throws this error. See `with-tramp-locked-connection`
macro. 

I got this problem with other minor modes too, but did not capture the
stack as I lowered the error prio via (add-to-list 'debug-ignored-errors
'remote-file-error). Reading the code would've suggested corruption
won't happen but still garbage was let in the stdio pipe and eglot lost track of the
buffer state.

--------------------------
In GNU Emacs 28.2 (build 1, x86_64-apple-darwin22.1.0, Carbon Version 169 AppKit 2299)
 of 2022-11-24 built on GDMBP.local
Windowing system distributor 'Apple Inc.', version 13.1.0
System Description:  macOS 13.1

Configured using:
 'configure --enable-locallisppath=/usr/local/share/emacs/site-lisp
 --infodir=/usr/local/Cellar/emacs-mac/emacs-28.2-mac-9.1/share/info/emacs
 --prefix=/usr/local/Cellar/emacs-mac/emacs-28.2-mac-9.1 --with-mac
 --enable-mac-app=/usr/local/Cellar/emacs-mac/emacs-28.2-mac-9.1
 --with-gnutls --with-modules'

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NOTIFY KQUEUE PDUMPER THREADS
TOOLKIT_SCROLL_BARS XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: TSX

Minor modes in effect:
  rainbow-delimiters-mode: t
  electric-pair-mode: t
  guru-mode: t
  subword-mode: t
  eglot--managed-mode: t
  flymake-mode: t
  popper-echo-mode: t
  popper-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  joro-mode: t
  doom-modeline-mode: t
  minions-mode: t
  override-global-mode: t
  global-flycheck-mode: t
  flycheck-mode: t
  global-hl-todo-mode: t
  hl-todo-mode: t
  which-function-mode: t
  global-company-mode: t
  company-mode: t
  helm-mode: t
  helm-minibuffer-history-mode: t
  helm-descbinds-mode: t
  helm--remap-mouse-mode: t
  async-bytecomp-package-mode: t
  ivy-mode: t
  editorconfig-mode: t
  winner-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  global-anzu-mode: t
  anzu-mode: t
  projectile-mode: t
  volatile-highlights-mode: t
  global-hl-line-mode: t
  super-save-mode: t
  windmove-mode: t
  recentf-mode: t
  savehist-mode: t
  save-place-mode: t
  show-smartparens-global-mode: t
  show-smartparens-mode: t
  smartparens-mode: t
  global-auto-revert-mode: t
  delete-selection-mode: t
  prelude-mode: t
  shell-dirtrack-mode: t
  which-key-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mac-mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/Users/gdanov/.emacs.d/elpa/cmake-mode-20221130.1357/cmake-mode hides /usr/local/share/emacs/site-lisp/cmake/cmake-mode
/Users/gdanov/.emacs.d/elpa/transient-20221119.1503/transient hides /usr/local/Cellar/emacs-mac/emacs-28.2-mac-9.1/share/emacs/28.2/lisp/transient

Features:
(shadow sort mail-extr emacsbug sendmail typescript-mode
cc-mode-expansions smartparens-c cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs eieio-opt speedbar
ezimage dframe helm-command bug-reference helm-x-files elisp-slime-nav
rainbow-delimiters elec-pair guru-mode subword-mode-expansions cap-words
superword subword eglot array jsonrpc ert debug flymake-proc flymake
ffap tramp-archive tramp-gvfs dbus helm-for-files helm-bookmark
helm-adaptive helm-external helm-net codespaces
use-package-ensure-system-package system-packages use-package
use-package-delight use-package-diminish tramp-theme em-dirs esh-var
esh-mode poly-markdown smartparens-markdown markdown-mode polymode
poly-lock polymode-base polymode-weave polymode-export polymode-compat
polymode-methods polymode-core polymode-classes eieio-custom eieio-base
graphql-mode let-alist org-jira org-jira-sdk jiralib request soap-client
url-http url-auth url-gw nsm rng-xsd xsd-regexp xml org-clock
the-org-mode-expansions org-element avl-tree smartparens-org 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 noutline outline
org-version ob-emacs-lisp ob-core ob-eval org-table oc-basic bibtex ol
org-keys oc org-compat org-macs org-loaddefs cal-menu calendar
cal-loaddefs git-link popper-echo popper magit-bookmark magit-submodule
magit-obsolete 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
magit-repos magit-apply magit-wip magit-log magit-diff smerge-mode
git-commit log-edit message rmc puny rfc822 mml mml-sec epa epg rfc6068
epg-config gnus-util rmail rmail-loaddefs mailabbrev mail-utils
gmm-utils mailheader add-log magit-core magit-autorevert magit-margin
magit-transient magit-process with-editor server magit-mode transient
magit-git magit-base magit-section crm compat-27 compat-26 prettier-js
web-mode-expansions web-mode disp-table smart-shift indent-tools
yafolding hydra lv indent-tools-indentation-of highlight-indentation
helm-cider-history helm-cider helm-cider-spec helm-cider-repl
helm-cider-cheatsheet helm-cider-util cider-cheatsheet cider cider-debug
cider-browse-ns cider-mode cider-find cider-inspector cider-completion
cider-profile cider-eval cider-jar arc-mode archive-mode
cider-repl-history pulse cider-repl cider-resolve cider-test
cider-overlays cider-stacktrace cider-doc cider-browse-spec
cider-clojuredocs cider-eldoc cider-client cider-common cider-connection
cider-util cider-popup sesman-browser nrepl-client nrepl-dict spinner
clojure-mode-expansions smartparens-clojure sesman clojure-mode align
parseedn parseclj-parser parseclj-lex parseclj-alist posframe
doom-modeline doom-modeline-segments doom-modeline-env
doom-modeline-core all-the-icons all-the-icons-faces data-material
data-weathericons data-octicons data-fileicons data-faicons
data-alltheicons shrink-path f f-shortdoc shortdoc s minions
doom-themes-ext-org doom-themes-ext-treemacs doom-themes-ext-neotree
doom-themes-ext-visual-bell face-remap doom-one-theme doom-themes
doom-themes-base nlinum linum helm-ring helm-ls-git derived vc-git
helm-ag helm-xref use-package-bind-key bind-key rainbow-mode
quelpa-use-package quelpa mm-decode mm-bodies mm-encode help-fns
radix-tree use-package-ensure use-package-core prelude-modules
prelude-xml nxml-mode-expansions rng-nxml rng-valid rng-loc rng-uri
rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns
nxml-mode nxml-outln nxml-rap html-mode-expansions smartparens-html
sgml-mode facemenu dom nxml-util nxml-enc xmltok prelude-shell sh-script
smie executable prelude-emacs-lisp prelude-lisp prelude-programming
flycheck hl-todo compat compat-macs which-func prelude-css
prelude-company company-oddmuse company-keywords company-etags
company-gtags company-dabbrev-code company-dabbrev company-files
company-clang company-capf company-cmake company-semantic
company-template company-bbdb company prelude-helm-everywhere helm-mode
helm-misc helm-descbinds helm-eshell helm-elisp helm-eval edebug
backtrace find-func helm-info prelude-helm helm-projectile helm-files
image-dired image-mode exif helm-tags helm-buffers helm-occur helm-grep
helm-regexp helm-locate helm-types helm-imenu helm-utils helm-help helm
helm-global-bindings helm-easymenu helm-core async-bytecomp helm-source
helm-multi-match helm-lib async helm-config prelude-ivy two-column ivy
ivy-faces ivy-overlay colir color prelude-macos exec-path-from-shell
prelude-global-keybindings warnings prelude-editor editorconfig
editorconfig-core editorconfig-core-handle editorconfig-fnmatch
operate-on-number calc-bin calc-ext calc calc-loaddefs calc-macs diff-hl
smartrep log-view pcvs-util vc-dir ewoc vc vc-dispatcher diff-mode
winner undo-tree diff queue eshell esh-cmd esh-ext esh-opt esh-proc
esh-io esh-arg esh-module esh-groups esh-util re-builder whitespace
tabify browse-kill-ring midnight ediff ediff-merg ediff-mult ediff-wind
ediff-diff ediff-help ediff-init ediff-util dired-x anzu avy tramp-sh
projectile skeleton ibuf-macs find-dired dired dired-loaddefs lisp-mnt
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr grep
compile ibuf-ext ibuffer ibuffer-loaddefs bookmark text-property-search
pp expand-region text-mode-expansions er-basic-expansions
expand-region-core expand-region-custom flyspell ispell rect etags
fileloop generator xref project volatile-highlights hl-line super-save
windmove recentf tree-widget wid-edit savehist saveplace diminish
smartparens-config smartparens-text smartparens advice dash autorevert
filenotify delsel prelude-mode easy-mmode crux docker-tramp tramp-cache
tramp tramp-loaddefs trampver tramp-integration files-x tramp-compat
shell pcomplete comint ansi-color ring parse-time iso8601 time-date
ls-lisp format-spec thingatpt imenu-anywhere imenu pcase jka-compr
prelude-core epl prelude-ui which-key prelude-custom prelude-packages
cl-extra help-mode finder-inf rx info edmacro kmacro package browse-url
url url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs eieio-loaddefs password-cache json subr-x map
url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/mac-win mac-win 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 easymenu timer select scroll-bar mouse jit-lock
font-lock syntax 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 emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads kqueue mac
multi-tty make-network-process emacs)

Memory information:
((conses 16 1024998 582937)
 (symbols 48 64969 19)
 (strings 32 287822 163197)
 (string-bytes 1 9937920)
 (vectors 16 113430)
 (vector-slots 8 2200185 552812)
 (floats 8 1234 2058)
 (intervals 56 14261 3055)
 (buffers 992 43))