Skip to content

Commit

Permalink
WIP: Fix race condition in pdfmaker
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Watson committed Nov 2, 2022
1 parent ece0aa6 commit a9ea88a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { Logger } from '@kbn/core/server';
import moment from 'moment';
import * as Rx from 'rxjs';
import { timeout } from 'rxjs/operators';
import { finished, Writable } from 'stream';
import { promisify } from 'util';
import { Writable } from 'stream';
import { finished } from 'stream/promises';
import type {
RunContext,
TaskManagerStartContract,
Expand Down Expand Up @@ -377,7 +377,15 @@ export class ExecuteReportTask implements ReportingTask {

stream.end();

await promisify(finished)(stream, { readable: false });
try {
// FIXME: This is where the "Premature close" error is thrown!
await finished(stream, { readable: false });
} catch (err) {
// FIXME: Temporarily ignoring `ERR_STREAM_PREMATURE_CLOSE` errors because of a race condition that doesn't seem to be important. Before merging this should be fixed
if (err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
throw err;
}
}

report._seq_no = stream.getSeqNo()!;
report._primary_term = stream.getPrimaryTerm()!;
Expand Down

0 comments on commit a9ea88a

Please sign in to comment.