Subject: Re: bug#5924: 23.1; accept-process-output switching current-buffer

From: Uday S Reddy <[email-masked]>
Date: Thu, 20 May 2010 10:50:28 +0100

Stefan Monnier writes:

> I've just installed a change in the Emacs Bzr trunk so that the
> current-buffer is preserved when running the Elisp code of process
> filters and sentinels.  If you can try this code (or try the patch
> below) to see if it fixes your problem, it would be helpful.

Hi Stephan, Sorry for the delay in getting back to you.  I have now
compiled and tried the latest bzr version (revno 100368).  But, it
seems to that the problem persists.

Here is my current proxy for accept-process-output:

  (defsubst vm-accept-process-output (process)
    "Accept output from PROCESS.  The variable `vm-imap-server-timeout'
  specifies how many seconds to wait before timing out.  If a timeout
  occurs, typically VM cannot proceed."
    ;; protect against possible buffer change due to bug in Emacs
    (let ((buf (current-buffer))
	  (got-output (accept-process-output process vm-imap-server-timeout)))
      (if got-output
	  (when (not (equal (current-buffer) buf))
	    (if (string-lessp "24" emacs-version)
		;; the Emacs bug should have been fixed
		(message 
		 "Emacs process output error: Buffer changed to %s" 
		 (current-buffer)))
	    ;; recover from the bug
	    (set-buffer buf))
	(vm-imap-protocol-error "No response from the IMAP server"))))

and the error came up pretty much the first time I tried it:

  Emacs process output error: Buffer changed to saved IMAP mailhost.c 10:31:09

The current-buffer should have been "IMAP mailhost.c 10:31.40".  But
it switched to the "IMAP mailhost.c 10:31:09" (call it the "old
buffer") because its process sent some output.

I am attaching the contents of the old buffer.  I think the last line
would have been output while the current accept-process-output was
done.  (Note that this line came in a few seconds after the current
process got started.)

So, there appears to be some deeper problem than originally thought.

Cheers,
Uday

3RhcnRpbmcgSU1BUCBzZXNzaW9uIFRodSBNYXkgMjAgMTA6MzE6MDkgMjAxMA0KY29ubmVjdGlu
ODE3NSBVSUQgMjY0NzEpDQ0KVk0gT 0sgRmV0Y2ggY29tcGxldGVkLg0NClZNIFVJRCBGRVRDSCAy
starting IMAP session Thu May 20 10:31:09 2010
connecting to mailhost.cs.bham.ac.uk:143
connected for fetch
* OK IMAP4 Ready imap 0001cdf3

VM CAPABILITY

* CAPABILITY IMAP4 IMAP4REV1

VM OK CAPABILITY

VM LOGIN <parameters omitted>

VM OK Logged in.

VM SELECT "INBOX"

* FLAGS (\Answered \Flagged \Deleted \Seen \Draft forwarded filed redistributed ! $Forwarded 7350 7354 7391 signed * accept action plagiarism Junk NonJunk !@)

* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft forwarded filed redistributed ! $Forwarded 7350 7354 7391 signed * accept action plagiarism Junk NonJunk !@ \*)] Flags permitted.

* 2648 EXISTS

* 0 RECENT

* OK [UIDVALIDITY 1217243146] UIDs valid

* OK [UIDNEXT 26600] Predicted next UID

VM OK [READ-WRITE] Select completed.

VM UID FETCH 26471:26471 (RFC822.SIZE)

* 2594 FETCH (RFC822.SIZE 58175 UID 26471)

VM OK Fetch completed.

VM UID FETCH 26471:26471 (BODY.PEEK[])

* 2594 FETCH (UID 26471 BODY[] {58175}

)

VM OK Fetch completed.

VM NOOP

VM OK NOOP completed.

VM UID FETCH 26582:26582 (RFC822.SIZE)

* 2638 FETCH (RFC822.SIZE 2181 UID 26582)

VM OK Fetch completed.

VM UID FETCH 26582:26582 (BODY.PEEK[])

* 2638 FETCH (UID 26582 BODY[] {2181}

)

VM OK Fetch completed.

VM NOOP

VM OK NOOP completed.

VM UID FETCH 26471:26471 (RFC822.SIZE)

* 2594 FETCH (RFC822.SIZE 58175 UID 26471)

VM OK Fetch completed.

VM UID FETCH 26471:26471 (BODY.PEEK[])

* 2594 FETCH (UID 26471 BODY[] {58175}

)

VM OK Fetch completed.

VM NOOP

VM OK NOOP completed.

VM UID FETCH 26578:26578 (RFC822.SIZE)

* 2635 FETCH (RFC822.SIZE 52388 UID 26578)

VM OK Fetch completed.

VM UID FETCH 26578:26578 (BODY.PEEK[])

* 2635 FETCH (UID 26578 BODY[] {52388}

)

VM OK Fetch completed.

VM LOGOUT

* BYE Logging out

VM OK Logout completed.

Process IMAP<2> connection broken by remote peer
ending IMAP session Thu May 20 10:31:43 2010