-
-
Notifications
You must be signed in to change notification settings - Fork 487
fix: client updater #1632
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
Open
LaercioLeal
wants to merge
7
commits into
opentibiabr:main
Choose a base branch
from
LaercioLeal:fix-autoupdater
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: client updater #1632
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47b759a
Fix: client updater
LaercioLeal 07b9f44
fix: potential issues
LaercioLeal 63390e7
Fix: HTTP cancellation into the OK and Restart button handlers
LaercioLeal e17abfb
Fix: Restart button won’t actually restart while updaterWindow exists
LaercioLeal dd08712
Fix: Adding changeUrl guard flag for mobile testing
LaercioLeal 4a35f31
Merge branch 'main' into fix-autoupdater
majestyotbr 799a015
feat(updater): restrict local file scan to server roots and optimize …
LaercioLeal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Race condition: cache can be built without lock protection.
When
flock()fails to acquire the lock (another process is updating), the code closes$lockon line 53, waits 100ms, then tries to read the cache. If the cache still doesn't exist at line 60, it proceeds to build the cache without holding any lock, defeating the locking mechanism.Additionally, if this path is taken and cache is built, line 82 calls
flock($lock, LOCK_UN)on an already-closed resource.🐛 Proposed fix to maintain lock throughout cache building
// File locking to prevent race conditions $lock_file = $cache_file . ".lock"; $lock = fopen($lock_file, "w"); if (!flock($lock, LOCK_EX | LOCK_NB)) { // Another process is updating cache, wait and use existing cache - fclose($lock); usleep(100000); // 100ms if (file_exists($cache_file)) { $cache = json_decode(file_get_contents($cache_file), true); } + if (!$cache) { + // Wait for the lock if cache still not available + flock($lock, LOCK_EX); + // Re-check cache after acquiring lock + if (file_exists($cache_file)) { + $cache = json_decode(file_get_contents($cache_file), true); + } + } } if (!$cache) { $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); $cache = array(); foreach ($rii as $file) { // ... rest of cache building ... } file_put_contents($cache_file . ".tmp", json_encode($cache)); rename($cache_file . ".tmp", $cache_file); - - // Release lock - flock($lock, LOCK_UN); } - if (isset($lock) && is_resource($lock)) { - fclose($lock); - } + // Release lock and close handle + flock($lock, LOCK_UN); + fclose($lock); }🤖 Prompt for AI Agents