cubehouse / themeparks

Unofficial API for accessing ride wait times and schedules for Disneyland, Disney World, Universal Studios, and many more parks
MIT License
536 stars 126 forks source link

Library crashing after short time #320

Closed Vortec4800 closed 3 years ago

Vortec4800 commented 3 years ago

Context

Describe the bug I'm having a weird problem where the library is crashing on my server, but works fine on my workstation. My laptop is running macOS and the server is on Ubuntu 18, and both are running the same version of the library, the same app code, and the same version of Node (12). Even more annoying, the mocha tests run successfully on the server, so it must be some way I'm setting up the library in code. It doesn't crash right away, but waits a minute or two, seems to wait for something to time out after the initial setup.

Output The process crashes with:

TypeError: this.GetInitialState is not a function
    at Timeout.Start [as _onTimeout] (/var/parse/parse-server/node_modules/themeparks/lib/disney/couchbaseChannel.js:373:39)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

Sure enough I see this.GetInitialState on line 373 in your library, but I don't know why Node wouldn't let it work. Do you have any ideas?

cubehouse commented 3 years ago

Struggling to reproduce this I'm afraid!

I stuck a "process.exit(0)" into couchbaseChannel.js and it doesn't look like anything is loading the file anymore since we had to move everything away from the library directly accessing the wdw database.

There is a line "setTimeout(this.Start, 60 * 1000)", that I think should probably have "this.Start.bind(this)", which might be why it can't find the function. However! This shouldn't be called any more, so something is a miss!

Have you definitely updated the npm modules? If you check the package.json in node_modules/themeparks/ - does this match 5.1.44? Worth having a check of the scripts your server is using are correct. Check waltdisneyworldepcot.js and ensure it's using "hostedPark" as it's base.

Vortec4800 commented 3 years ago

Okay I'll do some more digging. I'm pretty sure it's all the latest, I deleted the package lock file and the npm modules dir and installed fresh, but it didn't seem to help. I'll go check all of that and see if I find anything that's not up to date.

Vortec4800 commented 3 years ago

Looks correct: "_resolved": "https://registry.npmjs.org/themeparks/-/themeparks-5.1.44.tgz",

I also looked at the epcot.js file and it starts with:

const HostedPark = require('../hostedPark');

/**
 * Walt Disney World Epcot
 * @class
 * @extends WaltDisneyWorldPark
 */
class WaltDisneyWorldEpcot extends HostedPark {

so that looks right as well.

I added a process.exit(0) in couchbaseChannel.js on the first line as well, and the process exits immediately, so something is calling into it. I changed from exit to throwing an error on the first line, and then ran in with node trace, here's what it says:

/var/parse/parse-server/node_modules/themeparks/lib/disney/couchbaseChannel.js:1
throw "Error";
^
Error
Thrown at:
    at /var/parse/parse-server/node_modules/themeparks/lib/disney/couchbaseChannel.js:1:1
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /var/parse/parse-server/node_modules/themeparks/lib/disney/couchbaseChannelDisney.js:1:26
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1035:10)

Maybe that will help you decipher?

cubehouse commented 3 years ago

Confused why this is only happening in one place and not the others! Are you doing anything fun like hot-loading in the library or anything strange? Or are you manually creating new Park objects in your codebase somewhere?

I've checked in some changes to master that remove all the old scripts, if you set your package.json to point to the github directly I wonder if that will work? I'll push out an update to npm if it does. We shouldn't have unused files kicking around anyway, though I am surprised they are somehow activating for you. Sadly the callstack doesn't reveal much to me to explain where it is being activated from.

Vortec4800 commented 3 years ago

I don't think I'm doing anything weird, though perhaps something changed in a recent release? This is my setup code, I use these shared park objects to ensure I don't create more than one.

const Themeparks = require("themeparks");
Themeparks.Settings.CacheWaitTimesLength = 4 * D_MINUTES; // Ensure cache expires before each check

// Shared state variables
const magicKingdomWDW = new Themeparks.Parks.WaltDisneyWorldMagicKingdom();
const epcot = new Themeparks.Parks.WaltDisneyWorldEpcot();
const hollywoodStudios = new Themeparks.Parks.WaltDisneyWorldHollywoodStudios();
const animalKingdom = new Themeparks.Parks.WaltDisneyWorldAnimalKingdom();
const magicKingdomDL = new Themeparks.Parks.DisneylandResortMagicKingdom();
const californiaAdventure = new Themeparks.Parks.DisneylandResortCaliforniaAdventure();

Let me try pointing to the head and we'll see if your latest changes help.

Vortec4800 commented 3 years ago

Mystery solved! I figured it out!

This is definitely my fault, but I really appreciate all the help you've been giving me. A while back I wrote some scripts to pull and log bus schedules, and that was trying to run. I didn't realize that this wasn't supported or available any more, until I updated my local workstation to your latest on master and that file was totally gone. After removing my bus code, everything works like normal - that was the problem. It may not be a bad idea to keep those old files as deleted anyway, you can always pull them back out of the git history if you need them later on.

I'll go ahead and close this, again thank you for all your help!

cubehouse commented 3 years ago

Aha! Yeh I'm afraid all that has been taken down, Disney are blocking access to the live database pretty heavily so we're avoiding everybody individually accessing it and causing unnecessary traffic unfortunately. Hopefully we will restore some of the fun features like the buses at a later date though :)