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

Pause and resume (In a quick succession) gets you lot of exceptions and an infinite loop #636

Closed
varunsharma27 opened this issue Feb 19, 2019 · 4 comments

Comments

@varunsharma27
Copy link
Contributor

varunsharma27 commented Feb 19, 2019

Doing pause and resume (In a quick succession) on demo gets you lot of exceptions :-

papaparse.js:733 Uncaught DOMException: Failed to execute 'readAsText' on 'FileReader': The object is already busy reading Blobs.
    at FileStreamer._readChunk (https://www.papaparse.com/resources/js/papaparse.js:733:21)
    at FileStreamer._nextChunk (https://www.papaparse.com/resources/js/papaparse.js:722:10)
    at FileStreamer.ChunkStreamer.parseChunk (https://www.papaparse.com/resources/js/papaparse.js:538:10)
    at FileStreamer._chunkLoaded (https://www.papaparse.com/resources/js/papaparse.js:743:9)
    at FileReader.<anonymous> (https://www.papaparse.com/resources/js/papaparse.js:1800:25)
FileStreamer._readChunk	@	papaparse.js:733
FileStreamer._nextChunk	@	papaparse.js:722
ChunkStreamer.parseChunk	@	papaparse.js:538
FileStreamer._chunkLoaded	@	papaparse.js:743
(anonymous)	@	papaparse.js:1800
load (async)		
FileStreamer.stream	@	papaparse.js:710
CsvToJson	@	papaparse.js:265
parseNextFile	@	papaparse.js:163
$.fn.parse	@	papaparse.js:113
(anonymous)	@	demo.js:103
dispatch	@	jquery.min.js:3
r.handle	@	jquery.min.js:3

And if you choose to handle them, like this :-

function stepFn(results, parser)
{
	stepped++;
	if (results)
	{
		parser.pause();
		try{
		parser.resume();
		} catch (e) {
			console.log(e);
		}
		if (results.data){
			array2 = array2.concat(results.data); // Just to check the data
			rowCount += results.data.length;
		}
		if (results.errors)
		{
			errorCount += results.errors.length;
			firstError = firstError || results.errors[0];
		}
	}
}

Then you get into an infinite loop with the same data.

It appears that resume should be waiting for previous pause to halt the parsing before continuing again.
It appears this wasn't the case before since Issue #321 talks about doing this to produce another bug (Cursor related).
I am using :-
Papa.LocalChunkSize = 10485
Otherwise you get :-

RangeError: Maximum call stack size exceeded
    at FileStreamer.ChunkStreamer.parseChunk (papaparse.js:491)
    at ParserHandle.resume (papaparse.js:1078)
    at stepFn (demo.js:212)
    at ParserHandle._config.step (papaparse.js:1017)
    at doStep (papaparse.js:1651)
    at Parser.parse (papaparse.js:1561)
    at ParserHandle.parse (papaparse.js:1058)
    at FileStreamer.ChunkStreamer.parseChunk (papaparse.js:489)
    at ParserHandle.resume (papaparse.js:1078)
    at stepFn (demo.js:212)
@econic
Copy link

econic commented Feb 19, 2019

Having the same issue after trying to pause and resume the parser within each step

varunsharma27 added a commit to varunsharma27/PapaParse that referenced this issue Feb 19, 2019
@yew2993
Copy link

yew2993 commented Mar 19, 2019

I found that calling pause and resume in a promise chain resolved this issue for me.

function step(fn) {
  return (results, parser) => {
    Promise.resolve().then(() => {
      parser.pause();
      fn(results);
    }).then(() => {
      parser.resume();
    })
  }
}

@varunsharma27
Copy link
Contributor Author

@yew2993 The issue is fixed in the PR, currently waiting merge. It happens because resume is not waiting for previous pause to halt the parsing before continuing again.

pokoli pushed a commit that referenced this issue Mar 19, 2019
@pokoli
Copy link
Collaborator

pokoli commented Mar 19, 2019

I've merged the PR so it should work correctly on master

@pokoli pokoli closed this as completed Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants