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

Unclosed streams caused FS error after calling jq.json 2048 times. #18

Open
zhangweis opened this issue Oct 11, 2020 · 4 comments
Open

Comments

@zhangweis
Copy link

zhangweis commented Oct 11, 2020

I've got FS error after 2048 times calling jq.json.
I debugged and found unclosed streams in FS.streams caused by https://github.com/fiatjaf/jq-web/blob/master/post.js#L20.
Below code can show the error.

jq.onInitialized.addListener(()=>{
    for (var i =0;i<4098;i++) {
        console.log(jq.json({ok:i},'.'));
    }
    console.log('ok')
})

You'll get
...
{ ok: 2046 }
Error: FS error
Error: FS error
..../jq.asm.bundle1.js:122
throw ex
^

Error: abort(Error: FS error). Build with -s ASSERTIONS=1 for more info.

@fiatjaf
Copy link
Owner

fiatjaf commented Oct 11, 2020

Do you know how to fix it?
Just calling FS.close on these streams?

@zhangweis
Copy link
Author

I've tried commenting the 2 lines and seems no negative impacts happened. Is it for large content or something?

@fiatjaf
Copy link
Owner

fiatjaf commented Oct 11, 2020

I don't remember. All I have are the same hints you do:

jq-web/post.js

Lines 17 to 21 in cf1752c

Module.callMain(flags.concat(filter))
// calling main closes stdout, so we reopen it here:
FS.streams[1] = FS.open('/dev/stdout', 577, 0)
FS.streams[2] = FS.open('/dev/stderr', 577, 0)

"calling main closes stdout, so we reopen here".

Maybe this means the negative impacts would only be felt in the second run?
Or maybe this was an emscripten bug that was fixed already, so main isn't closing the streams anymore as it did before, that's why they're being kept open now and causing issues.

@zhangweis
Copy link
Author

I'm using a fix like below and so far it works for me.

        var stream1,stream2;
        stream1=FS.open("/dev/stdout",577,0);stream2=FS.open("/dev/stderr",577,0);
        setTimeout(()=>{FS.close(stream1);FS.close(stream2);},10000);

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

2 participants