Subject: bug#62845: 29.0.90; nntp-with-open-group-function kills current buffer on timeout

From: Eric Abrahamsen <[email-masked]>
Date: Fri, 05 May 2023 17:03:35 -0700

Eli Zaretskii <[email-masked]> writes:

>> From: Eric Abrahamsen <[email-masked]>
>> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
>> Date: Wed, 26 Apr 2023 20:08:53 -0700
>> 
>> Andreas Schwab <[email-masked]> writes:
>> 
>> > commit 032969e8c65 "Don't have nntp-report signal an error"
>> 
>> Ooh, I knew this would end up being me. Give me a couple of days, it
>> might not be the weekend before I have time to dig through this.
>
> Eric,
>
> Any progress?  I'd like to make another pretest of Emacs 29 soon, and
> I'm waiting for this fix.  TIA.

Sorry this has been slow!

First of all, thanks very much to Andreas for pinpointing the cause of
this. I'd seen this before and looked for the cause a couple of times,
but obviously didn't look hard enough.

So in `nntp-finish-retrieve-group-infos' we have code that 
does this (with all the extraneous bits left out):

(with-current-buffer nntp-server-buffer
  (while <loop>
    <timer could kill nntp-server-buffer somewhere in here>
    (nntp-accept-response))
  (nnheader-strip-cr))

Where `nntp-accept-response' calls `nntp-report' if it can't find its
process, which it can't if `nntp-server-buffer` has been killed in the
interim.

`nntp-report' used to raise an error in this case, so it didn't matter
what happened afterwards. That error would derail the entire process of
Gnus checking for news/mail, so I took it out so that other servers
could continue doing their work even if this one had lost its
connection.

But then the current buffer of `with-current-buffer` is gone, which as
Andreas notes dumps us in the most-recently-used buffer, which could be
anything. The `nnheader-strip-cr' acts on that buffer, and terrible
things result.

Other code in this library checks if the timer has killed the process
buffer in the meantime. There's probably a safe solution in here
somewhere, but if you're looking for a reliable regression fix to
include in Emacs 29, it's probably best just to revert 032969e8c65. That
behavior is annoying, but at least not buggy.

WDYT?

Eric