Skip to content

Commit

Permalink
Merge pull request #146 from tablelandnetwork/joe/local-fix-shutdown
Browse files Browse the repository at this point in the history
(local) ensure shutdown cannot be run repeatedly
  • Loading branch information
joewagner committed May 30, 2024
2 parents 34f7e27 + 4aaa05d commit f9f56a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/local/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tableland/local",
"version": "3.0.1",
"version": "3.0.2",
"description": "Tooling to start a sandboxed Tableland network.",
"repository": {
"type": "git",
Expand Down
13 changes: 13 additions & 0 deletions packages/local/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LocalTableland {
readonly defaultRegistryPort: number = 8545;

#_readyResolves: Array<(value: unknown) => any> = [];
stopping: boolean = false;
config;
initEmitter;
ready: boolean = false;
Expand Down Expand Up @@ -349,12 +350,24 @@ class LocalTableland {

async shutdown(): Promise<void> {
try {
// need to ensure shutdown isn't run twice in parallel since SIGINT is
// sent repeatedly depending on where it originates
if (this.stopping) {
console.log("stopping...");
return;
}

this.stopping = true;
await this.shutdownValidator();
await this.shutdownRegistry();

this.#_cleanup();
this.stopping = false;
this.ready = false;
} catch (err: any) {
this.#_cleanup();
this.stopping = false;
this.ready = false;
throw new Error(
`unexpected error during shutdown: ${err.message as string}`
);
Expand Down

0 comments on commit f9f56a3

Please sign in to comment.