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

Application Error #1451

Closed
NameOfTheDragon opened this issue Dec 14, 2020 · 13 comments
Closed

Application Error #1451

NameOfTheDragon opened this issue Dec 14, 2020 · 13 comments

Comments

@NameOfTheDragon
Copy link

Oops, it looks like there's a server issue...

image

@Richienb
Copy link
Collaborator

@remy

@remy
Copy link
Owner

remy commented Dec 14, 2020

Looks like it's crashing quite often:

Screenshot 2020-12-14 at 16 10 11

2020-12-14T16:08:26.360267+00:00 app[web.1]: /app/routes/get.js:63
2020-12-14T16:08:26.360276+00:00 app[web.1]: if (user.copyright) {
2020-12-14T16:08:26.360278+00:00 app[web.1]: ^
2020-12-14T16:08:26.360278+00:00 app[web.1]:
2020-12-14T16:08:26.360279+00:00 app[web.1]: TypeError: Cannot read property 'copyright' of undefined
2020-12-14T16:08:26.360280+00:00 app[web.1]: at module.exports (/app/routes/get.js:63:12)
2020-12-14T16:08:26.360281+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-12-14T16:08:26.360282+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2020-12-14T16:08:26.360283+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2020-12-14T16:08:26.360283+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2020-12-14T16:08:26.360284+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2020-12-14T16:08:26.360284+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:354:14)
2020-12-14T16:08:26.360284+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:365:14)
2020-12-14T16:08:26.360285+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:410:3)
2020-12-14T16:08:26.360285+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)

@remy
Copy link
Owner

remy commented Dec 14, 2020

@Richienb didn't you do a refactor recently?

@Richienb
Copy link
Collaborator

@remy I did one three months ago.

@Richienb
Copy link
Collaborator

This issue only happens periodically - I am unable to reproduce it consistently.

@Richienb
Copy link
Collaborator

I (think I) found the problem: It's all to do with a Javascript quirk.

Here we assign response.locals.user by extending itself with the result of a promise.

response.locals.user = {
...response.locals.user,
...await loadJsonFile(path.join(__dirname, '..', 'users', `${response.locals.id}.json`))
}

Notice that we await it within the assignment. What do you think response.locals.user looks like while the promise is still pending?

It actually temporarily sets it to what is essentially undefined.

To fix it, we just need to await the data before the assignment:

const userData = await loadJsonFile(path.join(__dirname, '..', 'users', `${response.locals.id}.json`))
response.locals.user = {
...response.locals.user,
...userData
}

I've just set up a quick uptime page so we can track if this change did anything.

@remy
Copy link
Owner

remy commented Dec 14, 2020 via email

@Richienb
Copy link
Collaborator

cname lookup?

@remy
Copy link
Owner

remy commented Dec 14, 2020

Sorry, we're crossing messages.

That await won't return the user object until the promise has settled (so the refactor here shouldn't make any difference).

The user object is definitely undefined. If it were set to a promise it would pass the test for user.cooyright (because we can do prop lookups on a promise - regardless of whether the promise has settled or not).

@NameOfTheDragon
Copy link
Author

It seems to be working again now.

@remy
Copy link
Owner

remy commented Dec 14, 2020 via email

@privatedev11
Copy link

It's happened again today. 3/2/21 at 3:38 GMT
Screenshot (47)

@Richienb
Copy link
Collaborator

The last recorded downtime is on February 11, 2021. I believe this means the issue is now resolved.

@remy remy closed this as completed May 27, 2021
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