Skip to content

Commit

Permalink
Revert "WIP: Fix race condition in reporting plugin"
Browse files Browse the repository at this point in the history
This reverts commit 771f0b2befc208d28b8012172d7447acc29068d2.
  • Loading branch information
Thomas Watson committed Jan 9, 2023
1 parent 4e4c195 commit d18da9e
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import type { Logger } from '@kbn/core/server';
import moment from 'moment';
import * as Rx from 'rxjs';
import { timeout } from 'rxjs/operators';
import { Writable } from 'stream';
import { finished } from 'stream/promises';
import { setImmediate } from 'timers/promises';
import { finished, Writable } from 'stream';
import { promisify } from 'util';
import type {
RunContext,
TaskManagerStartContract,
Expand Down Expand Up @@ -378,16 +377,7 @@ export class ExecuteReportTask implements ReportingTask {

stream.end();

// FIXME: Wait for the stream to end so that we don't trigger `ERR_STREAM_PREMATURE_CLOSE` errors when calling `finished` below (see https://github.com/nodejs/node/issues/45281). Before merging this should be fixed!
await (async function pendingCallbacks() {
if ((stream as any)._writableState.pendingcb > 0) {
await setImmediate();
await pendingCallbacks();
}
})();

// FIXME: This is where the "Premature close" error is thrown!
await finished(stream, { readable: false });
await promisify(finished)(stream, { readable: false });

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

0 comments on commit d18da9e

Please sign in to comment.