You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In NodeJS (or in a browser), the smoldot client crashes if a chain is removed while awaiting for chain.nextJsonRpcResponse().
The issue is reproduced in this stackblitz with the following code
import*assmoldotfrom'smoldot';importfsfrom'node:fs';// Load a string chain specification.constchainSpec=fs.readFileSync('./westend.json','utf8');// A single client can be used to initialize multiple chains.constclient=smoldot.start();constchain=awaitclient.addChain({ chainSpec });chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"system_name","params":[]}');(async()=>{while(true){// Wait for a JSON-RPC response to come back. This is typically done in a loop in the background.console.log({jsonRpcResponse: awaitchain.nextJsonRpcResponse()});}})();setTimeout(()=>{console.log('will remove chain');// notice that when the chain is removed,// smoldot panics on chain.nextJsonRpcResponse()// see wasn-node Rust code// https://github.com/smol-dot/smoldot/blob/48864e7810746a55ba8aa7eb12156708f8630cc0/wasm-node/rust/src/lib.rs#L258chain.remove();},10_000);
And the output is
[smoldot] Smoldot v1.0.15
[smoldot] Chain initialization complete for westend2. Name: "Westend". Genesis hash: 0xe143…423e. State root hash: 0x7e92439a94f79671f9cade9dff96a094519b9001a7432244d46ab644bb6f746f. Network identity: 12D3KooWA5qfvRuf5WncnAk2CANCsnBzSjwLVeEnX5Wzc5yTU2kd. Chain specification or database starting at: 0x1deb…95c7 (#16847280)
[json-rpc-westend2] The JSON-RPC client has just called a JSON-RPC function from the legacy JSON-RPC API (system_name). Legacy JSON-RPC functions have loose semantics and cannot be properly implemented on a light client. You are encouraged to use the new JSON-RPC API <https://github.com/paritytech/json-rpc-interface-spec/> instead. The legacy JSON-RPC API functions will be deprecated and removed in the distant future.
{
jsonRpcResponse: '{"jsonrpc":"2.0","id":1,"result":"smoldot-light-wasm"}'
}
[sync-service-westend2] GrandPa warp sync finished to #17001662 (0xbfb4…753e)
[runtime-westend2] Finalized block runtime ready. Spec version: 9430. Size of `:code`: 1.2 MiB.
will remove chain
[smoldot] Shutting down chain westend2
Smoldot has panicked. This is a bug in smoldot. Please open an issue at https://github.com/smol-dot/smoldot/issues with the following message:
panicked at 'called `Option::unwrap()` on a `None` value', wasm-node/rust/src/lib.rs:258:10
Error
at panic (/home/projects/smoldot-panic/node_modules/smoldot/dist/mjs/internals/local-instance.js:76:23)
In NodeJS (or in a browser), the smoldot client crashes if a chain is removed while awaiting for
chain.nextJsonRpcResponse()
.The issue is reproduced in this stackblitz with the following code
And the output is
The
wasm-node
rust code seems to besmoldot/wasm-node/rust/src/lib.rs
Lines 253 to 258 in 48864e7
I'm not sure if there is a better way to implement the loop to await for JSON RPC responses.
The text was updated successfully, but these errors were encountered: