Skip to content

Commit e564a2a

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <[email protected]>
1 parent 535599c commit e564a2a

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lib/utils.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,39 @@ module.exports.test = {
193193
return function (key) {
194194
if (!fs.existsSync(dataFile)) {
195195
// Increase wait time for CI environments where form submission may be slower
196-
const waitTime = process.env.CI ? 30 * 1000 : 1 * 1000 // 30 seconds in CI, 1 second otherwise
197-
const pollInterval = 200 // Check every 200ms
196+
const waitTime = process.env.CI ? 45 * 1000 : 1 * 1000 // 45 seconds in CI, 1 second otherwise
197+
const pollInterval = 500 // Check every 500ms to reduce load
198198
const startTime = new Date().getTime()
199199

200-
// Poll for file existence using proper sleep mechanism
200+
// Poll for file existence with exponential backoff-style intervals
201+
let currentInterval = pollInterval
201202
while (new Date().getTime() - startTime < waitTime) {
202203
if (fs.existsSync(dataFile)) {
203204
break
204205
}
205-
// Use spawnSync to create a proper non-CPU-intensive delay
206-
if (os.platform() === 'win32') {
207-
spawnSync('ping', ['-n', '1', '-w', pollInterval.toString(), '127.0.0.1'], { stdio: 'ignore' })
208-
} else {
209-
spawnSync('sleep', [(pollInterval / 1000).toString()], { stdio: 'ignore' })
206+
207+
// Use a more efficient sleep mechanism
208+
try {
209+
if (os.platform() === 'win32') {
210+
// Use timeout command which is more reliable than ping
211+
spawnSync('timeout', ['/t', Math.ceil(currentInterval / 1000).toString()], { stdio: 'ignore' })
212+
} else {
213+
// Use sleep with fractional seconds for better precision
214+
spawnSync('sleep', [(currentInterval / 1000).toString()], { stdio: 'ignore' })
215+
}
216+
} catch (err) {
217+
// Fallback to setTimeout-based delay if system commands fail
218+
const end = new Date().getTime() + currentInterval
219+
while (new Date().getTime() < end) {
220+
// Small yield to prevent complete CPU lock
221+
if (new Date().getTime() % 10 === 0) {
222+
process.nextTick(() => {})
223+
}
224+
}
210225
}
226+
227+
// Gradually increase interval to reduce polling frequency over time
228+
currentInterval = Math.min(currentInterval * 1.2, 2000)
211229
}
212230
}
213231
if (!fs.existsSync(dataFile)) {

0 commit comments

Comments
 (0)