Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack errors with very large CSV files #92

Closed
gtracy opened this issue Mar 12, 2015 · 11 comments
Closed

Stack errors with very large CSV files #92

gtracy opened this issue Mar 12, 2015 · 11 comments
Labels

Comments

@gtracy
Copy link

gtracy commented Mar 12, 2015

I'm getting a RangeError when I read very large - 570k - CSV files.

Reading from myfile.csv

/..../node_modules/fast-csv/lib/parser/parser_stream.js:277
emit: function (event) {
^
RangeError: Maximum call stack size exceeded

I do not have the same problem when I write the file of this size - only when I turn around and read it back.

Here's the pattern I'm using :

var file_name = process.argv[2];
var instream = fs.createReadStream(file_name);
var readStream = csv.parse({headers:true});

readStream.on('data', function(data) {
// transform the data and write it to a new file
});

readStream.on('end', function() {
console.log('\ndone.');
});

instream.pipe(readStream);

@gtracy
Copy link
Author

gtracy commented Mar 12, 2015

Note that event if the on-data function does absolutely nothing, I'll still run into the RangeError

@doug-martin
Copy link
Contributor

What version of node are you using?

@gtracy
Copy link
Author

gtracy commented Mar 12, 2015

0.10.28

@phof
Copy link

phof commented Mar 12, 2015

+1, same issue here while running the following against a 6M lines csv file (1.51GB) on Node v0.10.33:

var output = fs.createWriteStream(resultFile, { encoding: 'utf-8' });
var input = fs.createReadStream(file);

csv
.fromStream(input, {headers: true})
.transform(function(obj, next){
    process.nextTick(function() {
        if(obj.TIMESTAMP) { obj.TIMESTAMP = moment(obj.TIMESTAMP, 'YYYYMMDDHHmmss.SSSZ').toISOString(); }
        return next(null, obj);
    });
});
.pipe(csv.createWriteStream({headers: true}))
.pipe(output);
/node_modules/fast-csv/lib/parser/parser_stream.js:277
    emit: function (event) {
                   ^
RangeError: Maximum call stack size exceeded

doug-martin added a commit to doug-martin/fast-csv that referenced this issue Mar 13, 2015
* Removed try catch from emit to allow bubbling up of errors to process, if one is thrown C2FO#93
    * This also fixed issue C2FO#92 where a loop was entered when `this.emit("error")` was called.
* Added new tests
@doug-martin doug-martin mentioned this issue Mar 13, 2015
doug-martin added a commit to doug-martin/fast-csv that referenced this issue Mar 13, 2015
* Removed try catch from emit to allow bubbling up of errors to process, if one is thrown C2FO#93
    * This also fixed issue C2FO#92 where a loop was entered when `this.emit("error")` was called.
* Added new tests
doug-martin added a commit to doug-martin/fast-csv that referenced this issue Mar 13, 2015
* Removed try catch from emit to allow bubbling up of errors to process, if one is thrown C2FO#93
    * This also fixed issue C2FO#92 where a loop was entered when `this.emit("error")` was called.
* Added new tests
@doug-martin
Copy link
Contributor

So I found the issue which had to do with emit calling itself if an error was thrown within an event listener. I changed this and removed the try catch from emit so the error should bubble up and added new tests to prevent any regressions.

Please let me know if the problem persists, but this was the only way I was able to reproduce.

-Doug

@doug-martin
Copy link
Contributor

I should note you will have to upgrade to v0.6.0 to get the fix.

@gtracy
Copy link
Author

gtracy commented Mar 17, 2015

awesome. i've verified the fix with my example.

thanks!

@doug-martin
Copy link
Contributor

Awesome...thanks for the bug report

-Doug

@phof
Copy link

phof commented Mar 17, 2015

v0.6.0 solved the issue, thank you!

@doug-martin
Copy link
Contributor

👍

@afanasy
Copy link

afanasy commented May 25, 2015

Solved for me too, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants