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

Timeout in DocHandle waitFor prevents process from exiting. #235

Open
dmaretskyi opened this issue Nov 29, 2023 · 3 comments
Open

Timeout in DocHandle waitFor prevents process from exiting. #235

dmaretskyi opened this issue Nov 29, 2023 · 3 comments

Comments

@dmaretskyi
Copy link

The waitFor helper called here is creating a setTimeout that doesn't get cleared which prevents the node.js process from exiting.

They can be seen when running wtfnode after creating documents with automerge.

I believe this could be fixed by adding another final CLOSED state to DocHandle and a method to Repo that transitions all doc handles into that state.

@sroze
Copy link

sroze commented Jan 1, 2024

I also had this issue of having automerge-repo processes not stopping with NodeJS. For each Repo I have created, I need to do the following to close down all intervals & sockets:

// Create your `Repo`
const adapter = new BrowserWebSocketClientAdapter(`ws://localhost:${PORT}`);
const repo = new Repo({
  network: [ adapter ],
  // ...
})

// I disconnect `Repo` from the server:
adapter.disconnect()
adapter.peerId = undefined; // if not done, it will reconnect automatically.
adapter.socket?.close();

// stop each handle
Object.values(repo.handles).forEach((handle) => {
  // @ts-ignore `stop` has been added manually through a patch
  handle.stop();
});

For context, here's DocHandle's stop method that I had to add through a patch:

stop() {
  this.#machine.stop();
}

Provided guidance and strong PoV on the right technical strategy, very happy to contribute the changes needed.

@sroze
Copy link

sroze commented Jan 1, 2024

@dmaretskyi @pvh it would be great to have your insights on this.

@pvh
Copy link
Member

pvh commented Jan 1, 2024

ah yeah, this is just unfinished work i haven't felt enough pain from to fix yet.

a repo.stop() would be a good short-term workaround but really we probably also want something like repo.allSynced() or something as well.

broadly speaking the design here is something along the lines of "for short-lived processes there should be a way to gracefully exit when a task is done" and i think the "when a task is done" is going to be the more involved part.

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

No branches or pull requests

3 participants