[PATCH] emacs: fix infloop in password-store--run
Kai Tetzlaff
pwstore at tetzco.de
Sun Feb 27 08:07:46 UTC 2022
Hello,
while using the emacs password-store.el package (latest version from
https://git.zx2c4.com/password-store with pass v1.7.4 on Windows/WSL2) I
found that certain commands (like password-store--run-generate,
password-store--run-remove) cause an infloop in:
(defun password-store--run (&rest args)
"Run pass with ARGS.
Nil arguments are ignored. Returns the output on success, or
outputs error message on failure."
(let ((output nil)
(slept-for 0))
(apply #'password-store--run-1 (lambda (password)
(setq output password))
(delq nil args))
(while (not output)
(sleep-for .1))
output))
The problem is the `(while (not output) (sleep-for .1))` loop which
never receives any output (from the supposedly asynchronous pass process
started via `password-store--run-1').
There seems to be a race condition as e.g. stepping through the code in
edebug never caused the issue. Also, and this seems really weird, the
issue didn't happen when adding passwords to the root directory of the
password store (i.e. not in a subdirectory). As mentioned above, I'm
running emacs in WSL2 on Windows so this might have an effect on timing.
While I'm no expert in emacs process handling, I found code in other
packages which solved the 'wait for async process output' problem by
using the process object returned from `password-store--run-1' to make
sure that process output gets seen/accepted by emacs and check for
the termination of the aync process. Applying this to
`password-store--run' results in:
(let ((output nil)
(slept-for 0)
(process (apply #'password-store--run-1
(lambda (password)
(setq output password))
(delq nil args))))
(accept-process-output process .1 nil t)
(while (process-live-p process)
(accept-process-output process .1 nil t))
output))
which, at least in my environment, fixes the issue.
I've CCed Ian who initially added the async handling in commit 7aa17d0.
Maybe he can comment on this?
A patch with the change shown above against current master is attached.
Best Regards,
Kai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-infloop-in-password-store-run.patch
Type: text/x-diff
Size: 1817 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20220227/8d6b2f1f/attachment.bin>
More information about the Password-Store
mailing list