I'm making a game using a Node.js + Express app on Heroku. When the page loads, the soundtrack (music) is fetched in 5 20MB .mp3 files. But sometimes, the request hangs and then throws error 'Request aborted'. It seems to have something to do with file size as it always happens when the large files are being fetched, but it only happens sometimes (like, 20% of the time).
Here is the simplified source code:
// server
const app = express();
app.get('/*',
function(req, res){
req.on('close', ()=>{ write('request complete'); });
if(req.url === '/'){
// load homepage
write('sending homepage...'); res.sendFile('homepage.html', {root: __dirname}, onerr); } else
{ // send the requested file
write(`sending ${req.url}...`); res.sendFile(`${req.url}`, {root: __dirname}, onerr); }
});
// client:
let ost = [1, 2, 3, 4, 5].map(num=>new Audio(`soundtrack${num}.mp3`));
// output (randomly aborts):
sending filename1.jpg...
request complete
sending filename2.jpg...
request complete
sending soundtrack1.mp3...
request complete
sending soundtrack2.mp3...
Error: Request aborted
at onaborted (/app/node_modules/express/lib/response.js:1052:15)
at exit (/app/server.js:7:27)
at process.onerr (/app/server.js:35:43)
I tried:
- importing body-parser and doing
app.use(bodyParserErrorHandler());
, but I wouldn't see any additional logs in stdout explaining the error.
- calling
NODE_ENV=dev DEBUG=body-parser:*
from the package.json start script
(ChatGPT advised me to do that but it didn't help either).
- I noticed some logs in stdout coming after the error, saying 'Error H18: Server Request Interrupted'. But since they come after it, they're probably a consequence rather than the cause of it. Still, here are the details about H18, they might matter:
An H18 signifies that the socket connected, and some data was sent; The error occurs in cases where the socket was destroyed before sending a complete response, or if the server responds with data before reading the entire body of the incoming request.
I examined the possible causes for this and it seems there is a problem in the https communication rather than the code itself. What might this be?