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

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

Closed
kratico opened this issue Sep 26, 2023 · 1 comment · Fixed by #1197
Closed

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

kratico opened this issue Sep 26, 2023 · 1 comment · Fixed by #1197

Comments

@kratico
Copy link

kratico commented Sep 26, 2023

[email protected] throws TypeError when client.terminate() is invoked after a chain emits Finalized block runtime ready...

> node index.mjs

[smoldot] Smoldot v2.0.2
[smoldot] Chain initialization complete for westend2. Name: "Westend". Genesis hash: 0xe143…423e. Network identity: 12D3KooWDuSPNJDyUioToz1hCNvDHUQEyg9jMCYwsWrYPfwpTvJU. Chain specification starting at: 0x1deb…95c7 (#16847280)
[sync-service-westend2] GrandPa warp sync finished to #17629883 (0x9790…abb0)
[runtime-westend2] Finalized block runtime ready. Spec version: 9430. Size of `:code`: 1.2 MiB.
[smoldot] Shutting down chain westend2
TypeError: Cannot read properties of undefined (reading 'reset')
    at eventCallback (file:///home/projects/smoldot-panic-prujtf/node_modules/smoldot/dist/mjs/internals/client.js:180:28)
    at reset_connection (file:///home/projects/smoldot-panic-prujtf/node_modules/smoldot/dist/mjs/internals/local-instance.js:255:17)
    at wasm://wasm/0124b52e:wasm-function[4047]:0xe31f2
    at wasm://wasm/0124b52e:wasm-function[3524]:0xd91b8
    at wasm://wasm/0124b52e:wasm-function[2699]:0xbc110
    at wasm://wasm/0124b52e:wasm-function[1207]:0x3c96a
    at wasm://wasm/0124b52e:wasm-function[1206]:0x3c715
    at wasm://wasm/0124b52e:wasm-function[7062]:0x19567b
    at wasm://wasm/0124b52e:wasm-function[1230]:0x3e463
    at wasm://wasm/0124b52e:wasm-function[1229]:0x3e132

This may be unrelated, but the very same code that produces the above error, sometimes, get stuck and keeps emitting GrandPa warp sync...

> node index.mjs

[smoldot] Smoldot v2.0.2
[smoldot] Chain initialization complete for westend2. Name: "Westend". Genesis hash: 0xe143…423e. Network identity: 12D3KooWRLTACg76yPXX6kVi4fRiHazbx8Zo1SdwtEDmkBZjcNXF. Chain specification starting at: 0x1deb…95c7 (#16847280)
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)
[smoldot] Smoldot v2.0.2. Current memory usage: 540 kiB. Average download: 0 B/s. Average upload: 14 B/s.
[sync-service-westend2] GrandPa warp sync idle at block #16847280 (0x0x1deb…95c7)

How to repro?

Stackblitz

import * as smoldot from 'smoldot';
import * as fs from 'node:fs/promises';

const chainSpec = await fs.readFile(
  new URL('./westend.json', import.meta.url),
  { encoding: 'utf8' }
);

const client = smoldot.start();

const chain = await client.addChain({ chainSpec });

chain.sendJsonRpc(
  JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'chainHead_unstable_follow',
    params: [true],
  })
);

while (true) {
  // wait for [runtime-westend2] Finalized block runtime ready. Spec version: ...
  if (
    JSON.parse(await chain.nextJsonRpcResponse()).method ===
    'chainHead_unstable_followEvent'
  )
    break;
}

chain.remove();

// will throw
await client.terminate();
@kratico kratico changed the title TypeError when calling client.terminate() after Finalized block runtime ready TypeError when calling client.terminate() after Finalized block runtime ready... Sep 26, 2023
@tomaka
Copy link
Contributor

tomaka commented Sep 26, 2023

This may be unrelated, but the very same code that produces the above error, sometimes, get stuck and keeps emitting GrandPa warp sync...

Yeah this is totally unrelated, but I'd be curious to know why the warp syncing gets stuck. I've recently refactored the warp sync state machine (#1060) and it's likely that some bugs got introduced. If you could open an issue with logs when it gets stuck 🙏


About the error itself: it's again a mistake in the JavaScript code.

In the absolute it wouldn't be a bad idea to add some tests. Unfortunately I would really prefer to not connect to a live network (by principle, the tests should succeed even if you're offline) and setting up things so that the tests can be run locally is kind of complicated.

Since this JavaScript code is pretty small and stable (since #529), I've instead been counting on the fact that it should become bug-free after a while. However, I also haven't spent the time properly testing things like the terminate function.

tomaka added a commit to tomaka/smoldot that referenced this issue Sep 28, 2023
github-merge-queue bot pushed a commit that referenced this issue Sep 28, 2023
…ock runtime ready...` (#1197)

* Fix `TypeError` when calling `client.terminate()` after `Finalized block runtime ready...` #1192

* PR link
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 a pull request may close this issue.

2 participants