Close remote databases after one-shot replication - #75
Conversation
|
Thank you very much for tracing this resource retention and preparing the fix. The diagnosis is convincing, and I agree that a temporary remote database should have an explicit owner and be closed after one-shot replication. I am currently finalising #76, which establishes the resource-ownership and replacement rules used by Commonlib, including the Trystero replicator, and substantially changes the surrounding lifecycle structure. During the rewrite and its end-to-end testing, quite a few issues have come to light in the P2P functionality. I still think the underlying idea was sound, but I have to admit that parts of the original implementation were not written particularly well. Could you revisit this PR after #76 has landed, review the lifecycle pattern there, and then rebase and update this fix against the resulting structure? The current tests already establish the central close-after-replication behaviour. When adapting it, I think we should also cover:
I am very glad that you found this long-running resource leak. Thank you for the careful investigation and contribution. |
|
Understood. I will wait until #76 has merged, then rebase #75 onto the resulting main branch and adapt the fix to the ownership pattern established there. I will extend the coverage to verify that:
I will update the existing PR rather than opening a replacement. |
Temporary remote PouchDB instances now have explicit ownership through connectivity checks and one-shot replication. Disposal completes before a retry or resurrection begins, and close failures are logged without changing the replication result.
437a0c0 to
84e48e3
Compare
|
Updated this PR after #76 landed and force-pushed the existing branch with The revised ownership flow now:
Validation completed:
|
Summary
PouchDBdatabase after one-shot replication settles.Why
Periodic replication creates a fresh HTTP
PouchDBinstance for every one-shot run. The replication handler was cancelled when it settled, but the database itself was never closed. PouchDB therefore retained every instance in its constructor-level destruction listener registry.A renderer heap snapshot taken after approximately 58 hours with a 60-second periodic interval contained 3,046 remote HTTP database instances, compared with four in a shorter-run snapshot. The growth rate closely followed the configured periodic replication interval.
The investigation and reproduction details are in obsidian-livesync#1034.
Implementation
openOneShotReplication()now owns the temporary remote database from the point at which connectivity succeeds and closes it infinally. Continuous replication is unchanged.Validation
LiveSyncReplicator.unit.spec.ts: 5 passed.TrysteroReplicatorP2PServer.ts.