Subject: bug#39187: Fwd: "Package refresh is already in progress, please wait..."

From: Stefan Kangas <[email-masked]>
Date: Sun, 22 Mar 2020 12:40:36 +0100

Stefan Kangas <[email-masked]> writes:

>>> > It looks like emacs does not properly handle package refreshes when
>>> > the internet connection has been killed in the middle of an
>>> > refresh.
>>> > 
>>> > I often get this message in that case and I can't call package
>>> > until I actually kill emacs and restart it.
> [...]
>> I think the fix here is simply to make sure that these processes times
>> out.
>
> Unless I'm missing something, it turns out that this is not that easy
> to do.  At least I couldn't figure out how to do it.  I found the
> following probably relevant bug:
>
>  bug#34607: url-retrieve-synchronously: TIMEOUT option value takes no effect
>
> For now at least, I'm giving up on finding a solution where url does
> the right thing and times out. 
>
> -----
>
> I see two ways forward:
>
> 1. Remove the warning and accept that we might launch several
>    processes doing the same update one after the other.  I would like
>    to avoid that on master, but it might be the least intrusive change
>    for emacs-27.
>   
> 2. When we run a refresh, save the current time.  If the user tries to
>    run another refresh, check if more than X seconds has elapsed since
>    the old one was started.  If it has been more than X seconds,
>    prompt the user to kill the old refresh and re-launch it.  It won't
>    be perfect, but it will be better than what we had before at least.
>
> Does anyone else have any ideas or preferences here?  Otherwise, I'll
> revert the change that exposed this bug on the emacs-27 branch, and
> implement the second change on master.

The more I've been looking at and thinking about this, the less
convinced I've been that it's a good idea to do something like (2).
It would not be a proper solution, but a hack, really.

The correct fix would be to make sure the connection times out.  But
I'm not sure that it's worth going deep into the guts of url.el right
now.

Lars has been working on a replacement library (with-url) which AFAIU
he hopes to merge in the coming months.  Without having looked at it
in great detail, it seems to me that we should try to make package.el
use the with-url library once it's merged.  Hopefully, that means that
timeouts will work properly.  (Otherwise, we can fix it.)

Once timeouts work, it would then be easy to reintroduce the warning
about duplicate package refreshes.

I have consequently done (1) instead also on master: the commit is now
reverted and this warning removed.  Please test that it now works as
expected, and thank you for your patience.

Best regards,
Stefan Kangas