GNU bug report logs - #11536
23.4; frequent spurious auto-save while typing

Previous Next

Package: emacs;

Reported by: Jim Paris <jim <at> jtan.com>

Date: Mon, 21 May 2012 21:24:02 UTC

Severity: normal

Tags: moreinfo

Found in version 23.4

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11536 in the body.
You can then email your comments to 11536 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#11536; Package emacs. (Mon, 21 May 2012 21:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jim Paris <jim <at> jtan.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 21 May 2012 21:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jim Paris <jim <at> jtan.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 23.4; frequent spurious auto-save while typing
Date: Mon, 21 May 2012 17:22:17 -0400
Hi,

I've had a recurring problem with various versions of emacs over the
years: as I type into a buffer, "Auto-saving...done" flashes repeatedly
in the minibuffer.  On some systems, it happens every few characters
that I type, while on other systems, it is less frequent (but still more
frequent than my auto-save-interval of 300 characters, or my
auto-save-timeout value of 30 seconds).

Setting auto-save-timeout to 0 makes the problem go away, so it is a
problem with the measuring of elapsed time.

I'm running "emacs -nw" in an xterm, and the frequency of the problem
has always varied quite a bit with my version of X server, Linux kernel,
emacs, etc, so I've long suspected that there is a race condition.  The
way I usually reproduce it is:
- run xterm
- run "emacs -nw foo.txt"
- hold down a key and notice how you see "auto-save" flashing
  occasionally even though you haven't hit 300 characters or been idle
  for 30 seconds.

I finally got around to looking for the bug, and think I may have
tracked it down as follows: (I'm unfamiliar with the emacs code, so
please forgive me if I'm stating the obvious or get something wrong)

Auto-save due to timeout interval is controlled by keyboard.c:read_char.
read_char calls dispnew.c:sit_for with the auto_save_timeout of e.g. 30
seconds.  If sit_for returns Qt (no input pending), then the autosave
happens.

sit_for works by calling process.c:wait_reading_process_output with the
same timeout.  After wait_reading_process_output returns, it returns
Qt if no input was pending.

So the auto-save problem that I'm seeing would occur if:
  - wait_reading_process_output returns before the timeout has expired
  - no input was received

I believe that this happens due to a race condition with SIGIO delivery
inside wait_reading_process_output, as follows.  Line numbers are from
process.c in debian's emacs23-23.4+1.  The pseudocode is roughly:

4707: while(1)
4737:    set &timeout to the remaining timeout
4739:    if time expired, break
4811:    set_waiting_for_input(&timeout)
4986:    select(..., &timeout)
5007:    if (time_limit && nfds == 0 && ! timeout_reduced_for_timers)
5008:      /* We wanted the full specified time, so return now.  */
5009:      break;
5010:    if (nfds < 0)
5011:      ...
5129:    if (no_avail || nfds == 0)
5130:      continue;

(I think the comment in 5008 is a typo and meant "We _waited_...")

The call to keyboard.c:set_waiting_for_input is essentially telling the
keyboard.c:input_available_signal handler to reset &timeout to zero in
the case of SIGIO.  However, consider what happens if a key is pressed
and SIGIO is received between set_waiting_for_input and select.
Then timeout will have been set to zero, and select will return
immediately with nfds == 0.  The check in 5007 will then break the
while loop, causing wait_reading_process_output to return immediately
without any data having been read -- triggering the auto-save back
in keyboard.c:read_char.

I've verified with systemtap that select() is indeed being called with a
timeout of 0, so I'm pretty sure that this is the problem.

It seems the fix is simple: remove lines 5007-5009.  It's a small
optimization that isn't necessary, because the later check at line 5129
already covers the case where nfds == 0.  Continuing the loop is fine,
because the top of the loop checks for an expired timeout and returns.
Alternately, the "break" in 5009 could be replaced with a "continue"
which would still go back up to double-check that the timeout was really
hit.

Removing the 5007-5009 check fixes the problem on all the systems I've
tried.

-jim

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/usr/share/emacs/23.4/etc/DEBUG.


In GNU Emacs 23.4.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.10)
 of 2012-04-07 on trouble, modified by Debian
configured using `configure  '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.4/site-lisp:/usr/share/emacs/site-lisp' '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall -DDEBIAN -O2' 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_MESSAGES: en_US
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: POSIX
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Text

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
ESC x r e p o r t - e m a c s - b u g RET

Recent messages:
Loading /etc/emacs/site-start.d/50octave3.2-emacsen.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs/site-start.d/70jim.el (source)...
Toggling menu-bar-mode off; better pass an explicit argument.
Ready.
Loading /etc/emacs/site-start.d/70jim.el (source)...done
Loading quail/latin-ltx...done
Loading /home/jim/.emacs.d/systemtap-mode.el (source)...done
Ready.
call-interactively: Text is read-only

Load-path shadows:
/usr/share/emacs/23.4/site-lisp/cmake/cmake-mode hides /usr/share/emacs/23.4/site-lisp/cmake-data/cmake-mode
/usr/share/emacs/23.4/site-lisp/cmake/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
/usr/share/emacs/23.4/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs23/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/23.4/lisp/textmodes/flyspell
/usr/share/emacs23/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/23.4/lisp/textmodes/ispell
/usr/share/emacs/23.4/site-lisp/octave3.2-emacsen/octave-inf hides /usr/share/emacs/23.4/lisp/progmodes/octave-inf
/usr/share/emacs/23.4/site-lisp/octave3.2-emacsen/octave-mod hides /usr/share/emacs/23.4/lisp/progmodes/octave-mod

Features:
(shadow sort mail-extr message sendmail ecomplete rfc822 mml mml-sec
password-cache mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util netrc
time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock sha1
hex-util hashcash mail-utils emacsbug systemtap-mode byte-opt bytecomp
byte-compile cc-awk cc-langs cl cl-19 cc-mode cc-fonts cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs regexp-opt quail help-mode
easymenu view emacs-goodies-el emacs-goodies-custom
emacs-goodies-loaddefs easy-mmode tooltip ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd font-setting tool-bar dnd fontset
image fringe lisp-mode register page menu-bar rfn-eshadow timer select
scroll-bar mldrag mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev loaddefs button minibuffer faces cus-face files
text-properties overlay md5 base64 format env code-pages mule custom
widget hashtable-print-readable backquote make-network-process dbusbind
system-font-setting font-render-setting gtk x-toolkit x multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11536; Package emacs. (Sat, 03 Nov 2012 15:50:02 GMT) Full text and rfc822 format available.

Message #8 received at 11536 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: Jim Paris <jim <at> jtan.com>
Cc: 11536 <at> debbugs.gnu.org
Subject: Re: bug#11536: 23.4; frequent spurious auto-save while typing
Date: Sat, 03 Nov 2012 23:46:36 +0800
Jim Paris <jim <at> jtan.com> writes:

> The call to keyboard.c:set_waiting_for_input is essentially telling the
> keyboard.c:input_available_signal handler to reset &timeout to zero in
> the case of SIGIO.  However, consider what happens if a key is pressed
> and SIGIO is received between set_waiting_for_input and select.
> Then timeout will have been set to zero, and select will return
> immediately with nfds == 0.  The check in 5007 will then break the
> while loop, causing wait_reading_process_output to return immediately
> without any data having been read -- triggering the auto-save back
> in keyboard.c:read_char.
>
> It seems the fix is simple: remove lines 5007-5009.  It's a small
> optimization that isn't necessary, because the later check at line 5129
> already covers the case where nfds == 0.  Continuing the loop is fine,
> because the top of the loop checks for an expired timeout and returns.

Thanks for the bug report and the analysis.  I couldn't reproduce the
problem, but off the top of my head the analysis is correct, so I've
made the change you suggested in trunk.




bug closed, send any further explanations to 11536 <at> debbugs.gnu.org and Jim Paris <jim <at> jtan.com> Request was from Chong Yidong <cyd <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 03 Nov 2012 16:40:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11536; Package emacs. (Mon, 05 Nov 2012 02:39:02 GMT) Full text and rfc822 format available.

Message #13 received at 11536 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: "Herbert J. Skuhra" <hskuhra <at> eumx.net>
Cc: Jim Paris <jim <at> jtan.com>, 11536 <at> debbugs.gnu.org
Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r110781: Fix a race condition
	in wait_reading_process_output (tiny change).
Date: Mon, 05 Nov 2012 10:35:24 +0800
"Herbert J. Skuhra" <hskuhra <at> eumx.net> writes:

> the changes in r110781 (and r110782) make Emacs hang on both Arch
> GNU/Linux (i686) and FreeBSD 9.1-PRERELEASE (i386), e.g: 
> when Wanderlust is checking IMAP4 mailboxes.
>
> Strace on GNU/Linux is showing a loop of:
>
> poll([{fd=5, events=POLLIN}, {fd=6, events=POLLIN}, {fd=7,
> events=POLLIN}, {fd=3, events=POLLIN}], 4, 0) = 0 (Timeout)
> pselect6(13, [12], [], NULL, {0, 0}, {NULL, 8}) = 0 (Timeout)
> clock_gettime(CLOCK_REALTIME, {1352071692, 886361097}) = 0
> clock_gettime(CLOCK_REALTIME, {1352071692, 886549522}) = 0
> recv(6, 0x887ea58, 4096, 0) = -1 EAGAIN (Resource temporarily
> unavailable)
>
> Ktrace on FreeBSD is showing a loop of:
>
> 11723 emacs-24.3.50 RET   poll 0
> 11723 emacs-24.3.50 CALL  pselect(0x13,0xbfbf98bc,0xbfbf983c,0,0xbfbf99f8,0)
> 11723 emacs-24.3.50 RET   pselect 0
> 11723 emacs-24.3.50 CALL  read(0x3,0x849a018,0x1000)
> 11723 emacs-24.3.50 RET   read -1 errno 35 Resource temporarily unavailable

OK.  I'm reverting the change and reopening Bug#11536.





Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 05 Nov 2012 02:39:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11536; Package emacs. (Mon, 23 Aug 2021 15:06:01 GMT) Full text and rfc822 format available.

Message #18 received at 11536 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Jim Paris <jim <at> jtan.com>
Cc: 11536 <at> debbugs.gnu.org
Subject: Re: bug#11536: 23.4; frequent spurious auto-save while typing
Date: Mon, 23 Aug 2021 17:04:49 +0200
Jim Paris <jim <at> jtan.com> writes:

> I've had a recurring problem with various versions of emacs over the
> years: as I type into a buffer, "Auto-saving...done" flashes repeatedly
> in the minibuffer.  On some systems, it happens every few characters
> that I type, while on other systems, it is less frequent (but still more
> frequent than my auto-save-interval of 300 characters, or my
> auto-save-timeout value of 30 seconds).

[...]

> I believe that this happens due to a race condition with SIGIO delivery
> inside wait_reading_process_output, as follows.  Line numbers are from
> process.c in debian's emacs23-23.4+1.  The pseudocode is roughly:

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

I seem to remember there being some work done in this area over the last
few years, so this may be fixed by now.  Are you still seeing this issue
in recent Emacs versions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 23 Aug 2021 15:06:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11536; Package emacs. (Tue, 21 Sep 2021 05:42:02 GMT) Full text and rfc822 format available.

Message #23 received at 11536 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Jim Paris <jim <at> jtan.com>
Cc: 11536 <at> debbugs.gnu.org
Subject: Re: bug#11536: 23.4; frequent spurious auto-save while typing
Date: Tue, 21 Sep 2021 07:40:52 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> I seem to remember there being some work done in this area over the last
> few years, so this may be fixed by now.  Are you still seeing this issue
> in recent Emacs versions?

More information was requested, but no response was given within a
month, so I'm closing this bug report.  If the problem still exists,
please respond to this email and we'll reopen the bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 11536 <at> debbugs.gnu.org and Jim Paris <jim <at> jtan.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 21 Sep 2021 05:42:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 19 Oct 2021 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 327 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.