-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: add a basic timeout of 5s to fetch elpa archive
New file core-emacs-ext.el This is a basic monkey-patch solution but it will do the job for now. The timeout amount is not configurable for now. Tested on 24.5 and 24.3.1 fixes #3284
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
;;; core-emacs-ext.el --- Spacemacs Core File | ||
;; | ||
;; Copyright (c) 2012-2014 Sylvain Benner | ||
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors | ||
;; | ||
;; Author: Sylvain Benner <sylvain.benner@gmail.com> | ||
;; URL: https://github.com/syl20bnr/spacemacs | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;;; License: GPLv3 | ||
(require 'core-spacemacs-buffer) | ||
|
||
;; for some reason with-eval-after-load does not work here in 24.3 | ||
;; maybe the backport is incorrect! | ||
(eval-after-load 'package | ||
'(progn | ||
(defun package-refresh-contents () | ||
"Download the ELPA archive description if needed. | ||
This informs Emacs about the latest versions of all packages, and | ||
makes them available for download. | ||
This redefinition adds a timeout of 5 seconds to contact each archive." | ||
(interactive) | ||
;; the first part is not available before Emacs 24.4 so we just ignore | ||
;; it to be safe. | ||
(unless (version< emacs-version "24.4") | ||
;; FIXME: Do it asynchronously. | ||
(unless (file-exists-p package-user-dir) | ||
(make-directory package-user-dir t)) | ||
(let ((default-keyring (expand-file-name "package-keyring.gpg" | ||
data-directory))) | ||
(when (and package-check-signature (file-exists-p default-keyring)) | ||
(condition-case-unless-debug error | ||
(progn | ||
(epg-check-configuration (epg-configuration)) | ||
(package-import-keyring default-keyring)) | ||
(error (message "Cannot import default keyring: %S" (cdr error))))))) | ||
(dolist (archive package-archives) | ||
(condition-case-unless-debug nil | ||
(with-timeout (5 (spacemacs-buffer/warning | ||
"Cannot contact archive %s (reason: timeout)" | ||
(cdr archive))) | ||
(package--download-one-archive archive "archive-contents")) | ||
(error (message "Failed to download `%s' archive." | ||
(car archive))))) | ||
(package-read-all-archive-contents)))) | ||
|
||
(provide 'core-emacs-ext) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 😠. This has broken
M-x list-packages
for me on Emacs 25.1…Can please refrain from advising essential core functions? That's a horrible thing to do, and a darn stupid idea, no matter what issue this could possibly fix.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaryorn is right. That's a very very bad idea...
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but emacs 25 is not officially supported and the commit message is clear, this is the solution for now tested on 24.3 and 24.5, we all know this is not a good thing but people waiting 120 seconds for their emacs to start is a bigger concern to me. I'll try to make the point upstream when I have some time.
Of course, you are welcome to open an issue or submit a PR, in any case we'll try to fix this quickly :-)
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr Then let them wait. That's a thousand times better than advising the core package function, risking breakage (and not just risking) of the entire thing.
If you're concerned about network connectivity then ping all archives with an aggressive timeout before calling
package-refresh-contents
. That's way safer than advising.4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the proposal, I'm all for reverting this monkey patching if there is another way!
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr In my opinion you should never have advised this code in the first place. You should never monkey patch core code, no matter what the issue is. It's always going to be worse with advises.
YMMV, obviously, but I can't deny that I've lost trust in Spacemacs to some degree. I had thought that there's a stricter attitude towards code quality, and bringing up Emacs 25 as excuse doesn't help.
I'm sorry that I did not open a PR to fix this issue, but at some point I'd like to expect Spacemacs to just work. After all, I have to get my own work done at some point…
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr It's considered as a bad idea indeed. Why not revert this change back, and then figure out if there are other alternatives. Like try to determine if the Emacs version 24.3/24.5 is running, then apply this snippet?
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaryorn I understand your point and of course I agree but there is no such thing as all white or all black. I pondered the pros and cons and I decided that for the tested versions of Emacs supported by Spacemacs the likelihood to break something is very, very, very ....... very low, so this solution is a valid temporary one and make a HUGE difference in first perception for people installing Spacemacs while Org elpa directory is down.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my point is this: low risk vs. high impact on UX.
Now when you are in development branch of both Spacemacs and Emacs, you cannot expect a perfect experience. If you loose faith in Spacemacs in such context then I cannot do anything for you, especially when the development is very fast and active.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now if we have a better solution, let's do it, this is a good time for this.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what about the proposal to determine first if Emacs 24 is running?
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ReneFroger The first improvement would be this, a quick guard for development version of Emacs, but ultimately I would rather see the ping solution proposed by @lunaryorn which seems to be a perfect one.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr I disagree respectfully. I do think that there is all white and all black in many things, and some things are simply wrong in any case. I think that advising core functions is one of these.
I understand that using development versions of Spacemacs and Emacs is risky, and that's not what I'm concerned about. I expect issues with this combination and I know how to deal with these.
It's the fact that you actually considered an advise as a acceptable solution for whatever issue that concerns me because it reveals an attitude towards quality that's fundamentally different from mine. UX is important, for sure, but in my opinion it's never so important that it should dominate of basic considerations of code quality.
I'm sorry if I'm overreacting, but it's not the first time I've been burned by advises, and I'm getting fed up. I'd go so far as to say that advises—or more precisely, the ability to advise even basic core functions—is one of the worst “features” of Emacs.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaryorn I agree with you on the fact that advising core function is bad, I apology for this. But let's agree to disagree on the unbreakable rule because pragmatism makes me look at the applied modifications and I cannot help but thinking that this is an educated modification and certainly not a big shot in the dark. But it misses a guard against version below 24.3 and above 24.5 I should have been more accurate on this one especially when it has been tested on 24.3.1 and 24.5.1 only, this is my take away.
No problem with overreacting, I prefer this than no reaction at all and let the code rot.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr Ok, now that restores my trust a bit☺️ and I'm sorry for my harsh words 😊 I think you're doing an awesome job with Spacemacs, and despite such little nuisances I'm absolutely enjoying it.
I'm going to delete my tweets about this issue, these were absolutely out of place, and I'm terribly sorry for these, too. 😞
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I added the guard proposed by @ReneFroger but I'll look into the ping solution tonight.
@lunaryorn no problem, we learn to know each other and the project needs people like you capable of raising the voice (as long as it's constructive :-D). I'm sure there are horrors lurking in Spacemacs code base, but rest assure that we'll try to fix them. Now I hope there is not too much of them...
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly a stupid question, but where is the 120 sec timeout coming from? I can't seem to find it in the emacs code.
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justbur this is the issue, I was not able to find any timeout configuration anywhere in url library and other places. I'm going to report it upstream (actually should have done that along with the patch...)
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr I guess that's just the default timeout of
connect
in Emacs' sources. At least,make-network-process
which appears to be the core primitive for network IO doesn't seem to support a connect timeout parameter. It does support asynchronous connections on some systems apparently, buturl
does not seem to make use of that either to enforce a timeout.4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr It must be really tough, when you genuinely care about your userbase, make a decision after considering all pros and cons, and then somebody just comes at you and start talking to you like you're some random nobody and do not know what you're doing at all. :( That's physically painful to see. Personally, I fully support this patch if it'll actually prevent the 2 minutes waiting before Spacemacs start (haven't experienced anything like that, though).
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaryorn I implemented a solution inspired by your idea to ping the domain, it is based on request.el. See d822241 and more precisely https://github.com/syl20bnr/spacemacs/blob/develop/core/core-configuration-layer.el#L189-L230
Thank you for the pointer :-)
4d87ea6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syl20bnr Thank you 😊