Skip to content

[BUG] Callback called multiple times #423

@olegario96

Description

@olegario96

Describe the bug
I'm currently using your lib to parsing a stream received from a S3 bucket. But after some time I've noticed the following error:

{
    "errorType": "Error",
    "errorMessage": "Callback called multiple times",
    "code": "ERR_MULTIPLE_CALLBACK",
    "stack": ["Error [ERR_MULTIPLE_CALLBACK]: Callback called multiple times", "    at CsvParserStream.afterTransform (_stream_transform.js:89:31)", "    at callNext (/var/task/node_modules/@fast-csv/parse/build/src/CsvParserStream.js:93:28)", "    at /var/task/node_modules/@fast-csv/parse/build/src/CsvParserStream.js:119:28", "    at CsvParserStream.transformRow (/var/task/node_modules/@fast-csv/parse/build/src/CsvParserStream.js:165:13)", "    at iterate (/var/task/node_modules/@fast-csv/parse/build/src/CsvParserStream.js:116:25)", "    at Immediate._onImmediate (/var/task/node_modules/@fast-csv/parse/build/src/CsvParserStream.js:97:40)", "    at processImmediate (internal/timers.js:456:21)", "    at process.topLevelDomainCallback (domain.js:137:15)"]
}

Parsing or Formatting?

  • Formatting
  • Parsing

To Reproduce
Here's the current coding that's triggering this error:

return new Promise((resolve): void => {
  stream
    .pipe(parseCsv())
    .on('data', async (row: string[]) => {
      buffer.push(row);
      if (buffer.length === this.bufferLimit) {
        const bufferToBeConsumed = buffer;
        buffer = [];
        await this.upsertCsvRowsByExportType(bufferToBeConsumed, filename);
      }
    })
    .once('end', async () => {
      if (buffer.length) {
        const bufferToBeConsumed = buffer;
        buffer = [];
        await this.upsertCsvRowsByExportType(bufferToBeConsumed, filename);
        resolve();
      }
    });
});

The lib isn't used in any other place.

Expected behavior
No error should occur during parsing process.

Screenshots
Screen Shot 2020-07-08 at 13 37 48

Desktop (please complete the following information):

  • Lambda function
  • Node Version 12.13
  • Lib Version 4.3.1

Additional context
Add any other context about the problem here.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions