Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .github/actions/find/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ configuration option.

**Optional** Bool - whether to capture screenshots of scanned pages and include links to them in the issue

#### `url_timeout_ms`

**Optional** Positive integer (maximum 2147483647) limiting each URL scan in milliseconds. Default: `120000` (2 minutes). Browser setup, navigation, selectors, plugins, and screenshots share this budget. Cleanup has up to five additional seconds, including forced termination.

A timed-out URL retains confirmed findings and is reported as incomplete; subsequent URLs use a fresh browser.
If process-tree recovery cannot be confirmed, the action stops instead of scanning further URLs.

#### `scans`

**Optional** Stringified JSON array of scans to perform. Core engines and local plugins use string names.
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/find/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ inputs:
description: 'Whether to ignore HTTPS errors when scanning URLs with self-signed certificates'
required: false
default: 'false'
url_timeout_ms:
description: 'Maximum time in milliseconds to scan each URL (excluding bounded cleanup)'
required: false
default: '120000'

outputs:
findings_file:
Expand Down
80 changes: 80 additions & 0 deletions .github/actions/find/src/browserCleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type playwright from 'playwright'
import {execFile, type ChildProcess} from 'node:child_process'
import * as core from '@actions/core'
import {Deadline} from './deadline.js'

export async function killServer(
server: playwright.BrowserServer,
safeUrl: string,
platform: NodeJS.Platform = process.platform,
): Promise<unknown> {
try {
await new Deadline(1000).run(() => server.kill())
} catch (error) {
core.error(`Accessibility scan browser cleanup failed for ${safeUrl}`)
const child = server.process()
const pid = child.pid
if (platform === 'win32') {
if (!pid || child.exitCode !== null || child.signalCode !== null) {
throw new Error(`Cannot verify cleanup of the browser process tree for ${safeUrl}`)
}
let onExit: () => void = () => {}
const exited = new Promise<void>(resolve => {
onExit = resolve
child.once('exit', onExit)
})
let taskkill: ChildProcess | undefined
try {
await new Deadline(1000).run(
() =>
new Promise<void>((resolve, reject) => {
taskkill = execFile('taskkill', ['/PID', String(pid), '/T', '/F'], error =>
error ? reject(error) : resolve(),
)
}),
)
if (child.exitCode === null && child.signalCode === null) {
await new Deadline(1000).run(() => exited)
}
} catch (killError) {
taskkill?.kill('SIGKILL')
throw new Error(`Cannot verify cleanup of the browser process tree for ${safeUrl}`, {cause: killError})
} finally {
child.removeListener('exit', onExit)
}
return error
}
if (!pid) throw new Error(`Cannot verify cleanup of the browser process group for ${safeUrl}`)
if (child.exitCode !== null || child.signalCode !== null) {
try {
process.kill(-pid, 'SIGKILL')
} catch (killError) {
if ((killError as NodeJS.ErrnoException).code !== 'ESRCH') {
throw new Error(`Cannot verify cleanup of the browser process group for ${safeUrl}`, {cause: killError})
}
}
} else {
let onExit: () => void = () => {}
const exited = new Promise<void>(resolve => {
onExit = resolve
child.once('exit', onExit)
})
try {
process.kill(-pid, 'SIGKILL')
} catch (killError) {
if ((killError as NodeJS.ErrnoException).code !== 'ESRCH') {
child.removeListener('exit', onExit)
throw new Error(`Cannot verify cleanup of the browser process group for ${safeUrl}`, {cause: killError})
}
}
try {
await new Deadline(1000).run(() => exited)
} catch (waitError) {
throw new Error(`Cannot verify cleanup of the browser process group for ${safeUrl}`, {cause: waitError})
} finally {
child.removeListener('exit', onExit)
}
}
return error
}
}
47 changes: 47 additions & 0 deletions .github/actions/find/src/deadline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export class TimeoutError extends Error {
constructor() {
super('URL deadline exceeded')
this.name = 'TimeoutError'
}
}

export class Deadline {
readonly controller = new AbortController()
private readonly end: number

constructor(milliseconds: number) {
this.end = performance.now() + milliseconds
}

remaining() {
return Math.max(0, this.end - performance.now())
}

async run<T>(operation: () => Promise<T>): Promise<T> {
const remaining = this.remaining()
if (this.controller.signal.aborted || remaining === 0) {
this.controller.abort()
throw new TimeoutError()
}

let timer: ReturnType<typeof setTimeout> | undefined
try {
const result = await Promise.race([
Promise.resolve().then(operation),
new Promise<never>((_, reject) => {
timer = setTimeout(() => {
this.controller.abort()
reject(new TimeoutError())
}, remaining)
}),
])
if (this.remaining() === 0) {
this.controller.abort()
throw new TimeoutError()
}
return result
} finally {
clearTimeout(timer)
}
}
}
Loading