Skip to content

Commit

Permalink
Fix panic when removing a chain while querying next response (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored Aug 13, 2023
1 parent 1986f83 commit ba53e57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fix panic when removing a chain while a networking connection is being opened. ([#1011](https://github.com/smol-dot/smoldot/pull/1011))
- Fix epoch start slot calculation when epochs have been skipped. ([#1015](https://github.com/smol-dot/smoldot/pull/1015))
- Fix timeouts not working properly in the networking. ([#1023](https://github.com/smol-dot/smoldot/pull/1023), [#1026](https://github.com/smol-dot/smoldot/pull/1026))
- Fix panic when calling `Chain.remove` while `Chain.nextJsonRpcResponse` is in progress. ([#1025](https://github.com/smol-dot/smoldot/pull/1025))

## 1.0.15 - 2023-08-08

Expand Down
9 changes: 4 additions & 5 deletions wasm-node/javascript/src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,11 @@ export function start(options: ClientOptions, wasmModule: SmoldotBytecode | Prom
}
},
nextJsonRpcResponse: async () => {
if (!state.chains.has(chainId))
throw new AlreadyDestroyedError();
if (options.disableJsonRpc)
return Promise.reject(new JsonRpcDisabledError());

while (true) {
if (!state.chains.has(chainId))
throw new AlreadyDestroyedError();
if (options.disableJsonRpc)
return Promise.reject(new JsonRpcDisabledError());
if (state.instance.status === "destroyed")
throw state.instance.error;
if (state.instance.status !== "ready")
Expand Down
5 changes: 3 additions & 2 deletions wasm-node/javascript/src/internals/remote-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ export async function startInstanceServer(config: ServerConfig, initPortToClient
// from within the events callback itself.
// TODO: do better than setTimeout?
setTimeout(() => {
const numAccepted = state.acceptedJsonRpcResponses.get(event.chainId)!;
if (numAccepted == 0)
const numAccepted = state.acceptedJsonRpcResponses.get(event.chainId);
if (numAccepted === undefined || numAccepted === 0)
return;
const response = state.instance!.peekJsonRpcResponse(event.chainId);
if (response) {
Expand Down Expand Up @@ -345,6 +345,7 @@ export async function startInstanceServer(config: ServerConfig, initPortToClient
break;
}
case "remove-chain": {
state.acceptedJsonRpcResponses.delete(message.chainId);
state.instance!.removeChain(message.chainId);
break;
}
Expand Down

0 comments on commit ba53e57

Please sign in to comment.