diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index ca3ba4445f940a4..6d0d59d4d5c1480 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -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, @@ -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()!;