-
Notifications
You must be signed in to change notification settings - Fork 701
fix(cli): avoid Windows update check crash #455
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| // @ts-check | ||
|
|
||
| const fs = require('fs'); | ||
| const https = require('https'); | ||
| const path = require('path'); | ||
|
|
||
| const { program } = require('playwright-core/lib/tools/cli-client/program'); | ||
|
|
@@ -56,20 +57,32 @@ async function checkForUpdates() { | |
| } | ||
|
|
||
| async function fetchLatestVersion() { | ||
| const agent = new https.Agent({ keepAlive: false }); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's specifically how the crash happens:
this is why the version appears before the crash
technically it would probably be better to replace some/all of the but this is also arguably correct since there's no need to keep the connection alive any longer note there is an upstream fix for this nodejs/node#61999 but it has not been put into any release yet and i think this affects as far back as Node 23 |
||
| try { | ||
| const controller = new AbortController(); | ||
| const timeout = setTimeout(() => controller.abort(), 1500); | ||
| try { | ||
| const res = await fetch(`https://registry.npmjs.org/${packageJson.name}/latest`, { signal: controller.signal }); | ||
| if (!res.ok) | ||
| return undefined; | ||
| const json = await res.json(); | ||
| return typeof json.version === 'string' ? json.version : undefined; | ||
| } finally { | ||
| clearTimeout(timeout); | ||
| } | ||
| const body = await new Promise((resolve, reject) => { | ||
| const request = https.get(`https://registry.npmjs.org/${packageJson.name}/latest`, { agent }, response => { | ||
| const statusCode = response.statusCode || 0; | ||
| if (statusCode < 200 || statusCode >= 300) { | ||
| response.resume(); | ||
| reject(new Error(`Unexpected status code ${statusCode}`)); | ||
| return; | ||
| } | ||
| let body = ''; | ||
| response.setEncoding('utf8'); | ||
| response.on('data', chunk => body += chunk); | ||
| response.on('error', reject); | ||
| response.on('end', () => resolve(body)); | ||
| }); | ||
| const timeout = setTimeout(() => request.destroy(new Error('Request timed out')), 1500); | ||
| request.on('error', reject); | ||
| request.on('close', () => clearTimeout(timeout)); | ||
| }); | ||
| const json = JSON.parse(body); | ||
| return typeof json.version === 'string' ? json.version : undefined; | ||
| } catch { | ||
| return undefined; | ||
| } finally { | ||
| agent.destroy(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
why a new agent?
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.
i felt this was clearer than relying on the default/global agent implicitly having
keepAlive: false