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

add cleanup method to graph, use node v11, fix tests #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mguida22
Copy link

@mguida22 mguida22 commented Sep 21, 2020

Hello!

We've been using sharedstreets-js at RideReport for a couple months now, and it's been a great help to build on the shared streets reference system! Thanks all of the work that has gone into this!

I've included a few changes here that we had to make to get sharedstreets-js working for our use cases. Feel free to use these changes, modify them, or ignore them.

  • add a note that sharedstreets-js requires node v11 due to it's dependency on OSRM
  • fix the ordering of expect statements within test_core
  • add a cleanup method to the graph

The only real functionality change is adding a cleanup method.

When a graph is built, it creates a LevelDB database to use. This node process puts a lock on the database, but doesn't release the lock until the node process ends (usually the node script finishes running, or if there's some error). This causes an issue when the same node process wants to get a new graph instance, built off of the same inputs. When a second graph is built with the same input parameters, it attempts to use the existing LevelDB, but sees the lock and throws an error.

/Users/mike/oss/sharedstreets-js/node_modules/levelup/lib/levelup.js:119
      return callback(new OpenError(err))
                      ^
OpenError: IO error: lock /Users/mike/.shst/cache/graphs/e8958d1c-1464-373e-b6b8-5a4959e309d2/db/LOCK: already held by process
    at /Users/mike/oss/sharedstreets-js/node_modules/levelup/lib/levelup.js:119:23
    at /Users/mike/oss/sharedstreets-js/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
    at /Users/mike/oss/sharedstreets-js/node_modules/deferred-leveldown/deferred-leveldown.js:31:21
    at /Users/mike/oss/sharedstreets-js/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
Emitted 'error' event at:
    at /Users/mike/oss/sharedstreets-js/node_modules/levelup/lib/levelup.js:60:19
    at /Users/mike/oss/sharedstreets-js/node_modules/levelup/lib/levelup.js:119:14
    at ers/mike/oss/sharedstreets-js/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
    at /Users/mike/oss/sharedstreets-js/node_modules/deferred-leveldown/deferred-leveldown.js:31:21
    at /Users/mike/oss/sharedstreets-js/node_modules/abstract-leveldown/abstract-leveldown.js:38:14

This issue can be avoided by calling .close() on an open db connection when it's done being used.

These changes expose a .cleanup() method on the Graph, that closes the LevelDB connection. Once .cleanup() is called on an instance, a new instance can be created that accesses the same data. This allows for one continuous process to create and cleanup multiple sharedstreets Graphs.

(a lot of whitespace changes got included by my editor, let me know if you want me to remove them)

Comment on lines +648 to +657
/**
* closes the LevelDB connection, which removes the lock so that others
* can now connect to the same file.
*/
async cleanup() {
if (!this.db) return;

return await this.db.close();
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change to add a .cleanup method

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

Successfully merging this pull request may close these issues.

None yet

1 participant