-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Incorrect stream handling in Node v14 #515
Comments
The first 404 error is ok, it's not the reason you see the error. The actual problem is that all the JavaScript files are nt loaded by the browser. Can you please try running the example like this:
Then you'll receive more detailled debug information in the console. You can display even more log entries (the ones generated by express) with this command:
|
I tried the two commands above without any information, the app hangs on this request:
So I tried the tests and e2e:tests and they pass. |
Ok I finnaly found what is going on. It is due to the node version. I tried in another machine running node v10 or v12 and everything is ok. When I switch to node v14 I can't use almost any content with the js fetches never fulfilled. I think the e2e tests don't test the |
Thank you for your very helpful investigation and sorry you had all this trouble. I‘ll investigate why Node 14 breaks things soon. |
I've identified the cause of the issue: It seems like subscribing to the 'end' event in the Express controller breaks piping the stream to Express. You have to remove stream.on('end', () => {
res.end();
}); from ExpressController.getLibraryFile. However, I'm pretty certain that I've inserted these lines because it didn't work without it in the past. I'll have to read a bit about piping streams in Express to be able to write a fix. This might also apply to other endpoints that return streams. If anyone out there knows why and how the behaviour of streams has changed in Node v14, I'd appreciate some clue. |
At the moment I have downgraded to node v12. Thanks for your investigations, I haven't seen any deprecation on node 12 that might help to figure out what is going on. |
Maybe this commit |
After some investigations, it seems that this caused by this commit: Changing 'end' event with 'close' event seems to fix the problem on v14 and v12 is still ok. Maybe a e2e test should be added for |
I agree, nodejs/node#32968 seems to be the culprit. However, the issue is supposed to be resolved with Node 14.1.0. I've tried it with Node 14.2.0 and it still doesn't work. It look like we have to fix this here. I now remember why I added the subscription in the first place: It is a speed optimization. Without ending the Express response stream manually on the file stream's 'end', requests simply took longer to complete. As the H5P client requests a lot of files sequentially, these few milliseconds per request added up to a noticable performance decrease. It looks like we'll have to sacrifice this speed optimization for the time being, as Node 14 compatibility is certainly something we should strive for. It's probably better to optimize by packing files into bundles, anyway. @JPSchellenberg what do you think? I agree about the e2e tests. I've had a bad feeling about their state for some time now. They should be redone in general, as they only test the plaer and basically use their own example server implementation, which we should scrap for the example implementation, which has become pretty comprehensive. They also requires a GUI to run, which makes it difficult to run on GitHub actions. So rewriting and extending them is something that should be done soon. |
This might have been fixed by a recent PR merge, in which stream piping was changed. @benabel can you confirm that this now works in your setup? |
That's fixed on my machine too, I tried v3.0.3 and master I can now add contents with both node 12 and 14. Thank you for your support @sr258, I close the issue. |
Regression in (private) ajax adapter branch |
Describe the bug
When running the example provided, I can't upload my contents taken from here:
https://exo.lyceum.fr/node/1
Environment:
To Reproduce
Steps to reproduce the behavior:
Screenshots
The text was updated successfully, but these errors were encountered: