Timeout tailscale funnel in verbose runs and surface command output
This commit is contained in:
37
src/index.ts
37
src/index.ts
@@ -81,20 +81,34 @@ const execFileAsync = promisify(execFile);
|
|||||||
|
|
||||||
type ExecResult = { stdout: string; stderr: string };
|
type ExecResult = { stdout: string; stderr: string };
|
||||||
|
|
||||||
async function runExec(command: string, args: string[], maxBuffer = 2_000_000): Promise<ExecResult> {
|
type ExecOptions = { maxBuffer?: number; timeoutMs?: number };
|
||||||
|
|
||||||
|
async function runExec(
|
||||||
|
command: string,
|
||||||
|
args: string[],
|
||||||
|
{ maxBuffer = 2_000_000, timeoutMs }: ExecOptions = {}
|
||||||
|
): Promise<ExecResult> {
|
||||||
// Thin wrapper around execFile with utf8 output.
|
// Thin wrapper around execFile with utf8 output.
|
||||||
if (globalVerbose) {
|
if (globalVerbose) {
|
||||||
console.log(`$ ${command} ${args.join(' ')}`);
|
console.log(`$ ${command} ${args.join(' ')}`);
|
||||||
}
|
}
|
||||||
const { stdout, stderr } = await execFileAsync(command, args, {
|
try {
|
||||||
maxBuffer,
|
const { stdout, stderr } = await execFileAsync(command, args, {
|
||||||
encoding: 'utf8'
|
maxBuffer,
|
||||||
});
|
encoding: 'utf8',
|
||||||
if (globalVerbose) {
|
timeout: timeoutMs
|
||||||
if (stdout.trim()) console.log(stdout.trim());
|
});
|
||||||
if (stderr.trim()) console.error(stderr.trim());
|
if (globalVerbose) {
|
||||||
|
if (stdout.trim()) console.log(stdout.trim());
|
||||||
|
if (stderr.trim()) console.error(stderr.trim());
|
||||||
|
}
|
||||||
|
return { stdout, stderr };
|
||||||
|
} catch (err) {
|
||||||
|
if (globalVerbose) {
|
||||||
|
console.error(danger(`Command failed: ${command} ${args.join(' ')}`));
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
return { stdout, stderr };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureBinary(name: string): Promise<void> {
|
async function ensureBinary(name: string): Promise<void> {
|
||||||
@@ -391,7 +405,10 @@ async function ensureFunnel(port: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logVerbose(`Enabling funnel on port ${port}…`);
|
logVerbose(`Enabling funnel on port ${port}…`);
|
||||||
const { stdout } = await runExec('tailscale', ['funnel', '--yes', '--bg', `${port}`], 200_000);
|
const { stdout } = await runExec('tailscale', ['funnel', '--yes', '--bg', `${port}`], {
|
||||||
|
maxBuffer: 200_000,
|
||||||
|
timeoutMs: 15_000
|
||||||
|
});
|
||||||
if (stdout.trim()) console.log(stdout.trim());
|
if (stdout.trim()) console.log(stdout.trim());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to enable Tailscale Funnel. Is it allowed on your tailnet?', err);
|
console.error('Failed to enable Tailscale Funnel. Is it allowed on your tailnet?', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user