-
Notifications
You must be signed in to change notification settings - Fork 0
P2: Service-aware upgrade coordination (stop/start service safely) #46
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,34 +58,37 @@ export async function downloadProxy(version: string, targetPath: string = PATHS. | |
| // Ensure directory exists | ||
| await fs.ensureDir(path.dirname(targetPath)); | ||
|
|
||
| const writer = fs.createWriteStream(targetPath); | ||
| const tmpPath = `${targetPath}.download`; | ||
| await fs.remove(tmpPath); | ||
|
|
||
| const writer = fs.createWriteStream(tmpPath); | ||
| const responseStream = await axios({ | ||
| url: downloadUrl, | ||
| method: 'GET', | ||
| responseType: 'stream' | ||
| }); | ||
|
|
||
| responseStream.data.pipe(writer); | ||
|
|
||
| await new Promise((resolve, reject) => { | ||
| writer.on('finish', resolve); | ||
| writer.on('error', reject); | ||
| }); | ||
| try { | ||
| responseStream.data.pipe(writer); | ||
|
||
|
|
||
| logger.info('Download complete.'); | ||
| await new Promise((resolve, reject) => { | ||
| writer.on('finish', resolve); | ||
| writer.on('error', reject); | ||
| }); | ||
|
|
||
| logger.info('Verifying checksum...'); | ||
| try { | ||
| const isValid = await verifyChecksum(targetPath, expectedChecksum); | ||
| logger.info('Download complete.'); | ||
|
|
||
| logger.info('Verifying checksum...'); | ||
| const isValid = await verifyChecksum(tmpPath, expectedChecksum); | ||
| if (!isValid) { | ||
| throw new Error('Checksum verification failed'); | ||
| } | ||
| logger.info('Checksum verified.'); | ||
|
|
||
| await fs.move(tmpPath, targetPath, { overwrite: true }); | ||
| } catch (err) { | ||
| logger.warn('Failed to verify checksum', err); | ||
| // If verification fails, we should probably remove the file | ||
| await fs.remove(targetPath); | ||
| logger.warn('Failed to download/verify proxy', err); | ||
| await fs.remove(tmpPath); | ||
| throw err; | ||
| } | ||
|
|
||
|
|
||
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.
issue (bug_risk): Handle errors from the HTTP response stream to avoid hanging on download failures.
The awaited promise only subscribes to
writerevents, so errors fromresponseStream.dataare ignored. If the readable stream errors, the writable may never emitfinish/error, leavingdownloadProxystuck on failed requests.Add an
errorlistener onresponseStream.datathat rejects the promise (and/or closeswriter), or usestream.pipeline(optionallypromisified) to handle backpressure and propagate errors in one place.