GNU bug report logs - #13999
24.3.50; rng-validate-while-idle -> (error "Selecting deleted buffer")

Previous Next

Package: emacs;

Reported by: Carsten Bormann <cabo <at> tzi.org>

Date: Tue, 19 Mar 2013 15:38:02 UTC

Severity: normal

Found in version 24.3.50

Done: Leo Liu <sdl.web <at> gmail.com>

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 13999 in the body.
You can then email your comments to 13999 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#13999; Package emacs. (Tue, 19 Mar 2013 15:38:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Carsten Bormann <cabo <at> tzi.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 19 Mar 2013 15:38:02 GMT) Full text and rfc822 format available.

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

From: Carsten Bormann <cabo <at> tzi.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Tue, 19 Mar 2013 16:35:23 +0100
Killing an nXML buffer sometimes leads to a repeated occurrence of the error:

Error in timer: (error "Selecting deleted buffer")

More detail:

Debugger entered--Lisp error: (error "Selecting deleted buffer")
  rng-validate-while-idle(#<killed buffer>)
  apply(rng-validate-while-idle #<killed buffer>)
  byte-code("r\301\302H\303H\"\210)\301\207" [timer apply 5 6] 4)
  timer-event-handler([t 0 1 500000 t rng-validate-while-idle (#<killed buffer>) idle 0])

I don't have a detailed procedure for reproducing this, yet.

At least, rng-validate-while-idle should kill the timer if the buffer
has been killed.

In GNU Emacs 24.3.50.1 (x86_64-apple-darwin, NS apple-appkit-1038.36)
 of 2013-03-17 on bob.porkrind.org
Bzr revision: 112062 jay.p.belanger <at> gmail.com-20130317001909-prx18039wq0qmiv4
Windowing system distributor `Apple', version 10.3.1187
Configured using:
 `configure --host=x86_64-apple-darwin --build=i686-apple-darwin
 --with-ns'





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Tue, 19 Mar 2013 15:57:01 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Carsten Bormann <cabo <at> tzi.org>
Cc: 13999 <at> debbugs.gnu.org
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Tue, 19 Mar 2013 23:55:02 +0800
On 2013-03-19 23:35 +0800, Carsten Bormann wrote:
> Killing an nXML buffer sometimes leads to a repeated occurrence of the error:
>
> Error in timer: (error "Selecting deleted buffer")

I have seen this error too. Would you be able to find a way to reproduce
it so that we can understand and fix it with more confidence? Thanks in
advance.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Tue, 19 Mar 2013 20:54:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Carsten Bormann <cabo <at> tzi.org>
Cc: 13999 <at> debbugs.gnu.org
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Tue, 19 Mar 2013 16:51:18 -0400
> Debugger entered--Lisp error: (error "Selecting deleted buffer")
>   rng-validate-while-idle(#<killed buffer>)
>   apply(rng-validate-while-idle #<killed buffer>)
>   byte-code("r\301\302H\303H\"\210)\301\207" [timer apply 5 6] 4)
>   timer-event-handler([t 0 1 500000 t rng-validate-while-idle (#<killed buffer>) idle 0])

Right, rng-validate-while-idle needs to check that its buffer is
still live.  Ideally it should also disable the corresponding timer if
the buffer died.
Could someone take care of it?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Wed, 20 Mar 2013 00:36:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Wed, 20 Mar 2013 08:33:58 +0800
On 2013-03-20 04:51 +0800, Stefan Monnier wrote:
> Right, rng-validate-while-idle needs to check that its buffer is
> still live.  Ideally it should also disable the corresponding timer if
> the buffer died.
> Could someone take care of it?

Last time I checked the timer is supposed to be removed after buffer
being killed. So this fix is not ideal but it gives us a hint that a
recipe might involve killing the buffer.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Wed, 20 Mar 2013 03:32:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Tue, 19 Mar 2013 23:29:39 -0400
>> Right, rng-validate-while-idle needs to check that its buffer is
>> still live.  Ideally it should also disable the corresponding timer if
>> the buffer died.
>> Could someone take care of it?
> Last time I checked the timer is supposed to be removed after buffer
> being killed.  So this fix is not ideal but it gives us a hint that a
> recipe might involve killing the buffer.

Yes, clearly a recipe would require killing the buffer in such a way
that the timer is not canceled.  While we may want to try and fix the
hole that lets this happen, I think it's still worthwhile to defensively
make rng-validate-while-idle check that the buffer is still live, since
the other problem may be anywhere in some unrelated code (potentially
external to Emacs) that let-binds kill-buffer-hook (for example).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Wed, 20 Mar 2013 04:33:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Wed, 20 Mar 2013 12:30:11 +0800
On 2013-03-20 11:29 +0800, Stefan Monnier wrote:
[snipped 8 lines]
> Yes, clearly a recipe would require killing the buffer in such a way
> that the timer is not canceled.  While we may want to try and fix the
> hole that lets this happen, I think it's still worthwhile to defensively
> make rng-validate-while-idle check that the buffer is still live, since
> the other problem may be anywhere in some unrelated code (potentially
> external to Emacs) that let-binds kill-buffer-hook (for example).

I fully agree. I'll see if I can get to the root of the problem while
the OP is finding a recipe. IOW, I'll take care of this bug.

Thanks.
Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Fri, 22 Mar 2013 09:58:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Fri, 22 Mar 2013 17:55:31 +0800
On 2013-03-20 12:30 +0800, Leo Liu wrote:
>> Yes, clearly a recipe would require killing the buffer in such a way
>> that the timer is not canceled.  While we may want to try and fix the
>> hole that lets this happen, I think it's still worthwhile to defensively
>> make rng-validate-while-idle check that the buffer is still live, since
>> the other problem may be anywhere in some unrelated code (potentially
>> external to Emacs) that let-binds kill-buffer-hook (for example).
>
> I fully agree. I'll see if I can get to the root of the problem while
> the OP is finding a recipe. IOW, I'll take care of this bug.

One possibility is the buffer is killed while timer-idle-list is
temporarily bound to nil, in this case the timer will be left in the
timer-idle-list and causing this error.

The code in rng-valid.el uses the following idiom to redisplay without
triggering idle timers.

(let ((timer-idle-list nil))
   ....
   (sit-for 0)
   ....)

Is there a way to do this without let-binding timer-idle-list?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Fri, 22 Mar 2013 13:39:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Fri, 22 Mar 2013 09:36:36 -0400
> The code in rng-valid.el uses the following idiom to redisplay without
> triggering idle timers.

Why does it need to do that?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Fri, 22 Mar 2013 14:42:04 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Fri, 22 Mar 2013 22:39:29 +0800
On 2013-03-22 21:36 +0800, Stefan Monnier wrote:
>> The code in rng-valid.el uses the following idiom to redisplay without
>> triggering idle timers.
>
> Why does it need to do that?
>
>
>         Stefan

Does the following make any sense?

(defun rng-validate-while-idle-continue-p ()
  ;; input-pending-p and sit-for run timers that are
  ;; ripe.  Binding timer-idle-list to nil prevents
  ;; this.  If we don't do this, then any ripe timers
  ;; will get run, and we won't get any chance to
  ;; validate until Emacs becomes idle again or until
  ;; the other lower priority timers finish (which
  ;; can take a very long time in the case of
  ;; jit-lock).
  (let ((timer-idle-list nil))
    (and (not (input-pending-p))
	 ;; Fake rng-validate-up-to-date-end so that the mode line
	 ;; shows progress.  Also use this to save point.
	 (let ((rng-validate-up-to-date-end (point)))
	   (goto-char rng-validate-display-point)
	   (when (not rng-validate-display-modified-p)
	     (restore-buffer-modified-p nil))
	   (force-mode-line-update)
	   (let ((continue (sit-for 0)))
	     (goto-char rng-validate-up-to-date-end)
	     continue)))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Fri, 22 Mar 2013 17:37:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Fri, 22 Mar 2013 13:34:01 -0400
>>> The code in rng-valid.el uses the following idiom to redisplay without
>>> triggering idle timers.
>> Why does it need to do that?
> Does the following make any sense?

No, I don't understand what problem this is trying to avoid.
If noone understands this hack, I suggest to get rid of this
let-binding, and if/when the corresponding problem ever appears, we'll
see about fixing it some other way.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Sat, 23 Mar 2013 01:50:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sat, 23 Mar 2013 09:47:29 +0800
On 2013-03-23 01:34 +0800, Stefan Monnier wrote:
> No, I don't understand what problem this is trying to avoid.
> If noone understands this hack, I suggest to get rid of this
> let-binding, and if/when the corresponding problem ever appears, we'll
> see about fixing it some other way.

I get rid of it for now.

Carsten, will you be able to test out the new rng-valid.el¹²? Thanks.

Footnotes: 
¹  http://repo.or.cz/w/emacs.git/blob_plain/HEAD:/lisp/nxml/rng-valid.el
²  http://repo.or.cz/w/emacs.git/blob_plain/HEAD:/lisp/nxml/rng-nxml.el




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Sat, 23 Mar 2013 03:31:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sat, 23 Mar 2013 11:28:30 +0800
On 2013-03-20 11:29 +0800, Stefan Monnier wrote:
> I think it's still worthwhile to defensively make
> rng-validate-while-idle check that the buffer is still live, since the
> other problem may be anywhere in some unrelated code (potentially
> external to Emacs) that let-binds kill-buffer-hook (for example).

Let-binding kill-buffer-hook is also a source of problems like this bug
report. There are three places in emacs that do this:

  international/mule.el
  emacs-lisp/edebug.el
  gnus/mml.el

Looks like a really bad idea.

Most uses of kill-buffer-hook are cleanup routines. Let-bind the hook to
nil has a high probability of leaving things in an inconsistent state.

I think we should find a way to fix the three occurrences in emacs and
put a note in kill-buffer-hook's doc-string.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Sat, 23 Mar 2013 07:57:01 GMT) Full text and rfc822 format available.

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

From: Carsten Bormann <cabo <at> tzi.org>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 13999 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sat, 23 Mar 2013 08:54:08 +0100
On Mar 23, 2013, at 02:47, Leo Liu <sdl.web <at> gmail.com> wrote:

> On 2013-03-23 01:34 +0800, Stefan Monnier wrote:
>> No, I don't understand what problem this is trying to avoid.
>> If noone understands this hack, I suggest to get rid of this
>> let-binding, and if/when the corresponding problem ever appears, we'll
>> see about fixing it some other way.
> 
> I get rid of it for now.
> 
> Carsten, will you be able to test out the new rng-valid.el¹²? Thanks.
> 
> Footnotes: 
> ¹  http://repo.or.cz/w/emacs.git/blob_plain/HEAD:/lisp/nxml/rng-valid.el
> ²  http://repo.or.cz/w/emacs.git/blob_plain/HEAD:/lisp/nxml/rng-nxml.el

Well, how do you test that...
I played around with background-validating an XML file, scrolling while that happens, and that seems to work.
I don't use stealthy jit-lock etc., though, and my XML files are of moderate size (couple hundred kB), so maybe I'm not in the target group addressed by the original hack.

It seems really solving the problem the code was trying to address would require having a priority scheme for idle timer work: Validation happens in idle time but may be higher priority than other idle timer work.  Another way of blocking other idle timer work while doing sit-for/input-pending-p would, of course, also help; this might need exposing the READABLE_EVENTS_DO_TIMERS_NOW flag from input-pending-p and sit-for.

Grüße, Carsten





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Sat, 23 Mar 2013 14:16:02 GMT) Full text and rfc822 format available.

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

From: Leo Liu <sdl.web <at> gmail.com>
To: Carsten Bormann <cabo <at> tzi.org>
Cc: 13999 <at> debbugs.gnu.org
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sat, 23 Mar 2013 22:13:11 +0800
On 2013-03-23 15:54 +0800, Carsten Bormann wrote:
> Well, how do you test that...
> I played around with background-validating an XML file, scrolling
> while that happens, and that seems to work.
> I don't use stealthy jit-lock etc., though, and my XML files are of
> moderate size (couple hundred kB), so maybe I'm not in the target
> group addressed by the original hack.
>
> It seems really solving the problem the code was trying to address
> would require having a priority scheme for idle timer work: Validation
> happens in idle time but may be higher priority than other idle timer
> work. Another way of blocking other idle timer work while doing
> sit-for/input-pending-p would, of course, also help; this might need
> exposing the READABLE_EVENTS_DO_TIMERS_NOW flag from input-pending-p
> and sit-for.
>
> Grüße, Carsten

OK thanks for the information. I use nxml even less. I only use it to
edit plist files on OSX which are small in general. So I'll assume it is
good enough.

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13999; Package emacs. (Sat, 23 Mar 2013 16:13:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 13999 <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sat, 23 Mar 2013 12:10:29 -0400
> Let-binding kill-buffer-hook is also a source of problems like this bug
> report.

Let-binding a hook is generally a bad idea, yes.  It's even difficult to
ensure that it actually does what one intended.


        Stefan




Reply sent to Leo Liu <sdl.web <at> gmail.com>:
You have taken responsibility. (Sun, 24 Mar 2013 06:55:02 GMT) Full text and rfc822 format available.

Notification sent to Carsten Bormann <cabo <at> tzi.org>:
bug acknowledged by developer. (Sun, 24 Mar 2013 06:55:03 GMT) Full text and rfc822 format available.

Message #52 received at 13999-done <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 13999-done <at> debbugs.gnu.org, Carsten Bormann <cabo <at> tzi.org>
Subject: Re: bug#13999: 24.3.50;
	rng-validate-while-idle -> (error "Selecting deleted buffer")
Date: Sun, 24 Mar 2013 14:51:54 +0800
Fixed in trunk.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 21 Apr 2013 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 14 days ago.

Previous Next


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