Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding timeout when fetching plugin & more clear plugin error message #3389

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Neko-Box-Coder
Copy link
Contributor

Currently the http.Get() can hang for a long time, which also has no user feedback when doing something like micro -plugin available

Adding a timeout can tell the user which repo/channel is taking a long time, hence be able to inform the maintainer or troubleshoot it.

Also changed the error message for plugins to tell which part has failed to parse, which makes it easier to troubleshoot as well

if err != nil {
fmt.Fprintln(out, "Failed to query plugin repository:\n", err)
fmt.Fprintln(out, "Failed to query plugin repository", pr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors returned when retrieving plugins and channels are printed so I do not see why it would not be done with repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong edit when testing, corrected it back. Thanks

if err != nil {
fmt.Fprintln(out, "Failed to query plugin channel:\n", err)
fmt.Fprintln(out, "Failed to query plugin channel ", pc, " with error:\n", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space is printed between arguments when calling fmt.Fprintln so space does not have to be added at start or end of arguments. I tried testing a bit using Go 1.15 and 1.19 but URL was included in the error when running server using OpenBSD nc where nothing is sent. Are there errors where URL is not included?

It may also be already clear that messages like this are errors even if "with error" is not written:

Failed to query plugin channel:
 Get "http://localhost:8080": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you are right, I have reverted the changes back, thanks.

@Neko-Box-Coder Neko-Box-Coder force-pushed the PluginTimeout branch 2 times, most recently from 389d446 to 2048d69 Compare August 4, 2024 09:04
@JoeKar
Copy link
Collaborator

JoeKar commented Aug 4, 2024

Taking #3413 into account isn't a timeout of 10s still a bit too much, before any further user action is possible?

@Neko-Box-Coder
Copy link
Contributor Author

Neko-Box-Coder commented Aug 4, 2024

@JoeKar

Ideally, I would want an UI feedback when downloading or something, but that would probably require async or something like that (Both with command line interface and inside the editor).

You are right 10 seconds could be a bit too short. Maybe I can put the http.get in a (fixed number of) loop where the timeout duration is increased (maybe doubled) every iteration?

Or should I just increase the timeout to like 20 or 30 seconds for now?

@JoeKar
Copy link
Collaborator

JoeKar commented Aug 4, 2024

Or should I just increase the timeout to like 20 or 30 seconds for now?

Not in case the user can't do anything in this moment. Waiting for 10s, without the possibility to proceed, could already being a long time.

Maybe the user could be ask if a retry shall take place with possible increased (duplicated timeout), because he should somehow know is connectivity?

@dmaluka
Copy link
Collaborator

dmaluka commented Aug 4, 2024

We can make the timeout arbitrarily long, as long as the user can easily interrupt it.

That requires more work to implement (to do the http request in a separate goroutine, cancel the http request, integrate it with the infobar event loop etc), but it seems worth doing?

(For the command-line case we don't need to do that.)

@JoeKar
Copy link
Collaborator

JoeKar commented Aug 4, 2024

That's another option.
But when it's started in a separate goroutine do we want to keep running in parallel and maybe succeed after 10 minutes and present the result? 🤔

@dmaluka
Copy link
Collaborator

dmaluka commented Aug 4, 2024

I didn't mean running it in the background while the user can do something else in the UI. I meant running it in the "foreground" from the user perspective, like we do now, but with something like "Downloading list of plugins, press Esc to interrupt".

@JoeKar
Copy link
Collaborator

JoeKar commented Aug 4, 2024

Ok, that sounds like the way to go and worth the effort. 👍

@Neko-Box-Coder
Copy link
Contributor Author

@dmaluka @JoeKar

Yeah... The suggestion is good but I think someone else maybe better off implementing it than me given I am not that familiar with the codebase and language 😅. golang is not my main language after all

The purpose of this PR is just to add a timeout (so that it can't hang indefinitely) and a better error message when failing to parse json (so that the user know which repo/channel has faulty json)

Maybe we can (finalize and) merge this in for now and someone can create a PR for the suggestion?

@Neko-Box-Coder
Copy link
Contributor Author

Hi @dmaluka @JoeKar

I have increased the timeout to 30 seconds, which should be enough for the majority of the plugins even if the internet is quite slow.

Also added a message to tell the user to wait before we do any fetching.

I would rather it hang for 30 seconds (for the time being) than getting hung forever, which would be bad if the user has any unsaved changes when doing plugin update in the editor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants