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

Fix TypeError when calling client.terminate() after Finalized block runtime ready... #1197

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix JavaScript error being thrown when `Client.terminate` is called while the client is not idle. ([#1197](https://github.com/smol-dot/smoldot/pull/1197))

## 2.0.2 - 2023-09-25

### Changed
Expand Down
14 changes: 9 additions & 5 deletions wasm-node/javascript/src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,18 @@ export function start(options: ClientOptions, wasmModule: SmoldotBytecode | Prom
if (state.instance.status !== "ready")
throw new Error(); // Internal error. Never supposed to happen.
state.instance.instance.shutdownExecutor();
state.instance = { status: "destroyed", error: new AlreadyDestroyedError() };

// Wait for the `executor-shutdown` event to be generated.
await new Promise<void>((resolve) => state.onExecutorShutdownOrWasmPanic = resolve);

// In case the instance crashes while we were waiting, we don't want to overwrite
// the error.
if (state.instance.status === "ready")
state.instance = { status: "destroyed", error: new AlreadyDestroyedError() };
state.connections.forEach((connec) => connec.reset());
state.connections.clear();
for (const addChainResult of state.addChainResults) {
addChainResult({ success: false, error: "Smoldot has crashed" });
addChainResult({ success: false, error: "Client.terminate() has been called" });
}
state.addChainResults = [];
for (const chain of Array.from(state.chains.values())) {
Expand All @@ -606,9 +613,6 @@ export function start(options: ClientOptions, wasmModule: SmoldotBytecode | Prom
chain.jsonRpcResponsesPromises = [];
}
state.chains.clear();

// Wait for the `executor-shutdown` event to be generated.
await new Promise<void>((resolve) => state.onExecutorShutdownOrWasmPanic = resolve);
}
}
}
Loading