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

feat(explorer): local indexer inside explorer #3229

Merged
merged 16 commits into from
Sep 25, 2024

Conversation

karooolis
Copy link
Contributor

@karooolis karooolis commented Sep 24, 2024

Local store indexer is now run as part of the Explorer package. It is skipped if the configured chain is non-anvil.

Copy link

changeset-bot bot commented Sep 24, 2024

🦋 Changeset detected

Latest commit: 6dee218

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@latticexyz/explorer Patch
create-mud Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/cli Patch
@latticexyz/common Patch
@latticexyz/config Patch
@latticexyz/dev-tools Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/protocol-parser Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/stash Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/store Patch
@latticexyz/utils Patch
@latticexyz/world-module-metadata Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch
mock-game-contracts Patch
ts-benchmarks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@karooolis karooolis changed the title chore(explorer): local indexer inside explorer feat(explorer): local indexer inside explorer Sep 24, 2024
@karooolis karooolis force-pushed the kumpis/indexer-inside-explorer branch from d538550 to 21659a9 Compare September 25, 2024 06:37
@@ -143,6 +171,9 @@ process.on("SIGINT", () => {
if (explorerProcess) {
explorerProcess.kill();
}
if (indexerProcess) {
indexerProcess.kill();
}
process.exit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this kill the subprocesses automatically?

Copy link
Contributor Author

@karooolis karooolis Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not, does indexer spawn subprocesses? wonder if we should use something like https://www.npmjs.com/package/terminate to stay on the safe side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By subprocesses I meant the things you're spawning here. I expect since this explorer bin process is the one spawning, it has a parent-child relationship, and would kill any of its children if the parent process got killed. But maybe that assumption is why a lot of my tools end up with hanging/zombie processes 🙈

Down to use something like terminate, but usage seems low, so I wonder if there's a more mainstream/battle-tested variant out there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, yeah terminate package does not seem widely used, and might be an overkill. Just looked into it a bit more and based on my understanding, keeping track of child processes, and then killing them once the parent process is killed is the way to do it. A common danger is spawning child processes but then not killing them explicitly once parent process is killed but we handle that with process.on("SIGINT") listener so should be good there. Then the child processes, once stopped, should themselves stop their own child processes but looks like we have no problems there since both explorer and store-indexer don't seem to leave anything hanging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about other signals like sigkill?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, thought I had everything. So turns out SIGKILL cannot be captured but SIGTERM can. So now capturing SIGINT and SIGTERM which captures it all to the best of my knowledge. Will do a bit more research into this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't help with sigkill but looks like we can listen to both sigint and sigterm with

process.on('exit', () => {
  ...
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried it and it's working. Checked the docs and it says The 'exit' event is emitted when the Node.js process is about to exit as a result of either: so it does make sense to clean up the child processes here based on the documentation, updated.

holic
holic previously approved these changes Sep 25, 2024
@karooolis karooolis merged commit 95aa3bb into main Sep 25, 2024
12 checks passed
@karooolis karooolis deleted the kumpis/indexer-inside-explorer branch September 25, 2024 13:04
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 this pull request may close these issues.

2 participants