[procrunner] avoid waiting for processes forever (#65909)

This commit is contained in:
Spencer 2020-05-11 11:04:23 -07:00 committed by GitHub
parent be7902311d
commit cbe559745a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9896 additions and 9874 deletions

View file

@ -18,17 +18,22 @@
*/
import moment from 'moment';
import { filter, first, catchError } from 'rxjs/operators';
import * as Rx from 'rxjs';
import { filter, first, catchError, map } from 'rxjs/operators';
import exitHook from 'exit-hook';
import { ToolingLog } from '../tooling_log';
import { createCliError } from './errors';
import { Proc, ProcOptions, startProc } from './proc';
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const noop = () => {};
interface RunOptions extends ProcOptions {
wait: true | RegExp;
waitTimeout?: number | false;
}
/**
@ -71,6 +76,7 @@ export class ProcRunner {
cwd = process.cwd(),
stdin = undefined,
wait = false,
waitTimeout = 15 * MINUTE,
env = process.env,
} = options;
@ -97,8 +103,8 @@ export class ProcRunner {
try {
if (wait instanceof RegExp) {
// wait for process to log matching line
await proc.lines$
.pipe(
await Rx.race(
proc.lines$.pipe(
filter(line => wait.test(line)),
first(),
catchError(err => {
@ -108,8 +114,18 @@ export class ProcRunner {
throw err;
}
})
)
.toPromise();
),
waitTimeout === false
? Rx.NEVER
: Rx.timer(waitTimeout).pipe(
map(() => {
const sec = waitTimeout / SECOND;
throw createCliError(
`[${name}] failed to match pattern within ${sec} seconds [pattern=${wait}]`
);
})
)
).toPromise();
}
if (wait === true) {

File diff suppressed because it is too large Load diff