I think this is probably a fairly simple fix, even though it's a lot of code...when the user starts loading into the app, it essentially sends a request to the server that calls a bunch of different APIs and sub functions, then returns some data queried from a Postgres table to the user. For some reason, About 40% of the time, I'm getting an H27 error thrown when the response is sent back to the user. The logs look like this:
2022-07-18T01:46:36.443368+00:00 app[web.1]: User is attempting to sign in
2022-07-18T01:46:36.443386+00:00 app[web.1]: Started processing
2022-07-18T01:46:36.883171+00:00 app[web.1]: Signing in from X,Y
2022-07-18T01:46:38.662059+00:00 app[web.1]: API Call 1,2,and 3
2022-07-18T01:46:40.416057+00:00 app[web.1]: API Call 4
2022-07-18T01:46:40.932732+00:00 app[web.1]: API Call 5
2022-07-18T01:46:40.949921+00:00 app[web.1]: API Call 6
2022-07-18T01:46:44.683997+00:00 app[web.1]: finished processing
2022-07-18T01:46:44.684014+00:00 app[web.1]: Sending 110 results back to the client
2022-07-18T01:46:44.694904+00:00 heroku[router]: sock=client at=warning code=H27 desc="Client Request Interrupted" method=POST path="/userLoadingInToApp" host=app-name.herokuapp.com request_id=11caaa97-4b27-431e-84bd-e8b82162877f fwd="xxx.xxx.xxx.xx" dyno=web.1 connect=0ms service=8343ms status=499 bytes= protocol=https
I print out 'Sending x results back to the client' RIGHT before sending the results back to the client, so because the H27 error is thrown after that, it only makes sense there is an error being thrown when trying to send response back to the client:
app.post('/userLoadingInToApp', async function (request, response) {
let results = await start(request) // All the calculations, database queries, api calls, console.logging etc are done inside this container function.
console.log(`Sending ${results.length} back to the client`)
response.send(results)
})
Often, the response is returned fine to the client, so not sure what's going on here...