Skip to content

Version check: bound the UI-thread download with an overall timeout - #1592

Merged
jw098 merged 2 commits into
mainfrom
version-check-timeout
Oct 16, 2026
Merged

jw098 merged 2 commits into
mainfrom
version-check-timeout

Conversation

@Gin890

@Gin890 Gin890 commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Clicking Settings (and program stop/startup) calls check_new_version() on the UI thread, which downloads LatestVersion.json synchronously. QNetworkRequest::setTransferTimeout(5s) only limits data transfer, not the connection phase, and the overall watchdog in download_file() is disabled (#if 0 in FileDownloader.cpp), so a connection that stalls to raw.githubusercontent.com blocks QEventLoop::exec() - and the UI thread - indefinitely. Symptom: the app hangs when Settings is clicked.

Adds an optional overall deadline to download_file()/download_json_file() (default: no limit, so resource downloads keep their current behavior) and gives the version check a 10 second budget; on expiry the reply is aborted and the existing OperationFailedException path skips the check.

Verified with a full Linux CI-style build (pa-build).

Clicking Settings (and program stop/startup, Main.cpp) calls
check_new_version() on the UI thread, which downloads
LatestVersion.json synchronously. QNetworkRequest::setTransferTimeout(5s)
only limits data transfer, not the connection phase, and the overall
watchdog in download_file() is disabled (#if 0), so a connection that
stalls to raw.githubusercontent.com blocks QEventLoop::exec() - and the
UI thread - indefinitely (the app appears to hang when Settings is
clicked).

Add an optional overall deadline to download_file()/download_json_file()
(default: no limit, so resource downloads keep their current behavior)
and give the version check a 10 second budget; on expiry the reply is
aborted and the existing OperationFailedException path skips the check.
logger,
"https://raw.githubusercontent.com/PokemonAutomation/ComputerControl/master/LatestVersion.json"
"https://raw.githubusercontent.com/PokemonAutomation/ComputerControl/master/LatestVersion.json",
std::chrono::seconds(10)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd reduce this to 3 seconds. Since it's not an important check.

// data transfer, so without it a connection that stalls would block
// this call forever). std::chrono::seconds(0) (the default) imposes no
// overall limit.
std::string download_file(Logger& logger, const std::string& url, std::chrono::seconds overall_timeout = std::chrono::seconds(0));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

line is getting long here. Break it into multiple lines.

// Throws OperationFailedException if failed to download.
// Returns empty value if invalid JSON.
JsonValue download_json_file(Logger& logger, const std::string& url);
JsonValue download_json_file(Logger& logger, const std::string& url, std::chrono::seconds overall_timeout = std::chrono::seconds(0));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

// Deadline for the whole request, including the connection phase
// (setTransferTimeout() above only limits data transfer). Without
// this, a connection that stalls would block loop.exec() forever.
QTimer overall_timer;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a real fan of QTimer since we're trying to minimize Qt usage. But this file is already littered with it. This is just a comment, you don't need to do anything.

@jw098

jw098 commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

This PR was accidentally generated by Gin's bot (i.e. I wanted it to fix one bug, but it found this bug instead). I'll take a look at your suggestions today or over the next few days.

@jw098
jw098 merged commit 6fa5bf2 into main Oct 16, 2026
14 checks passed
@jw098
jw098 deleted the version-check-timeout branch October 16, 2026 23:28
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.

3 participants