Coder Social home page Coder Social logo

Comments (13)

Richienb avatar Richienb commented on July 17, 2024

@remy

from mit-license.

remy avatar remy commented on July 17, 2024

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)

from mit-license.

remy avatar remy commented on July 17, 2024

@Richienb didn't you do a refactor recently?

from mit-license.

Richienb avatar Richienb commented on July 17, 2024

@remy I did one three months ago.

from mit-license.

Richienb avatar Richienb commented on July 17, 2024

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

from mit-license.

Richienb avatar Richienb commented on July 17, 2024

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.

from mit-license.

remy avatar remy commented on July 17, 2024

from mit-license.

Richienb avatar Richienb commented on July 17, 2024

cname lookup?

from mit-license.

remy avatar remy commented on July 17, 2024

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).

from mit-license.

NameOfTheDragon avatar NameOfTheDragon commented on July 17, 2024

It seems to be working again now.

from mit-license.

remy avatar remy commented on July 17, 2024

from mit-license.

privatedev11 avatar privatedev11 commented on July 17, 2024

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

from mit-license.

Richienb avatar Richienb commented on July 17, 2024

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

from mit-license.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.