Skip to content
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

fix: properly close scheduling timer to avoid checkly test hanging #770

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/cli/src/services/abstract-check-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export const DEFAULT_CHECK_RUN_TIMEOUT_SECONDS = 300

const DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS = 20000

const SCHEDULING_DELAY_EXCEEDED_TIMEOUT_KEY = 'SCHEDULING_DELAY_EXCEEDED'

export default abstract class AbstractCheckRunner extends EventEmitter {
checks: Map<CheckRunId, { check: any, testResultId?: string }>
testSessionId?: string
// If there's an error in the backend and no check result is sent, the check run could block indefinitely.
// To avoid this case, we set a per-check timeout.
timeouts: Map<CheckRunId, NodeJS.Timeout>
schedulingDelayExceededTimeout?: NodeJS.Timeout
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could put it in timeouts, but I prefer having a separate property

accountId: string
timeout: number
verbose: boolean
Expand Down Expand Up @@ -200,12 +199,27 @@ export default abstract class AbstractCheckRunner extends EventEmitter {
return
}
Array.from(this.checks.entries()).forEach(([checkRunId]) => this.disableTimeout(checkRunId))

if (this.schedulingDelayExceededTimeout) {
clearTimeout(this.schedulingDelayExceededTimeout)
this.schedulingDelayExceededTimeout = undefined
}
}

private startSchedulingDelayTimeout () {
this.timeouts.set(SCHEDULING_DELAY_EXCEEDED_TIMEOUT_KEY, setTimeout(() =>
this.emit(Events.MAX_SCHEDULING_DELAY_EXCEEDED), DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS,
))
let scheduledCheckCount = 0
const numChecks = this.checks.size
if (numChecks === 0) {
return
}
this.schedulingDelayExceededTimeout = setTimeout(
() => this.emit(Events.MAX_SCHEDULING_DELAY_EXCEEDED),
DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS,
)
this.on(Events.CHECK_INPROGRESS, () => {
scheduledCheckCount++
if (scheduledCheckCount === numChecks) clearTimeout(this.schedulingDelayExceededTimeout)
})
}

private disableTimeout (timeoutKey: string) {
Expand Down
Loading