fix: improve reconnection stability and fix resource leaks#384
Open
Yana-Hangabina wants to merge 1 commit into
Open
fix: improve reconnection stability and fix resource leaks#384Yana-Hangabina wants to merge 1 commit into
Yana-Hangabina wants to merge 1 commit into
Conversation
- Return undefined instead of throwing in _resolveById when VFS root is not initialized, preventing EntryNotFound crashes during reconnect - Reuse existing ClientManager and SCMCollectionProvider on reconnect instead of disposing and recreating them, which kills in-progress file sync operations and loses collaboration state - Add ClientManager.reconnect() to re-register socket event handlers on the new connection without full teardown - Increase socket emit and joinProject timeout from 5s to 15s to accommodate higher latency connections - Use .once() instead of .on() for connectionRejected in joinProject to prevent listener accumulation across reconnects - Dispose previous EventBus listener before registering new one in onConnectionAccepted handler to prevent memory leak - Log socket errors instead of throwing to avoid crashing the extension host - Guard removePosition calls in updateStatus forEach to prevent timer chain interruption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several bugs in the socket reconnection flow that cause crashes, lost file sync operations, and resource leaks. These issues affect all users but are more visible on unstable connections (closes #309).
Problems
_resolveByIdthrows when VFS root is uninitialized — during reconnect,this.rootis brieflyundefined. Any call to_resolveById(fromClientManager.removePosition, cursor tracking, etc.) throwsEntryNotFound, crashing the 500ms status timer chain. All callers already handleundefinedreturns via optional chaining.SCMCollectionProvider destroyed on every reconnect —
initializingPromiseunconditionally disposes and recreates bothClientManagerandSCMCollectionProviderafter each successfuljoinProject. This kills in-progressLocalReplicaSCMProvider.overwrite()(file sync), discards file watchers, and resets collaboration state.connectionRejectedlistener leak injoinProject— uses.on()instead of.once(), accumulating a new listener on everyjoinProjectcall. After ~10 reconnects, triggersMaxListenersExceededWarning.EventBus.on('socketioConnectedEvent')leak —updateEventHandlersregisters a newEventBuslistener foronConnectionAcceptedon every call without removing the previous one.5-second socket emit timeout — too aggressive for connections with non-trivial latency (proxy, remote servers).
joinDoccalls frequently time out, cascading into disconnects.errorhandler throws uncaught exceptions —initInternalHandlersthrows on socket errors, which can crash the extension host.Changes
src/core/remoteFileSystemProvider.ts_resolveByIdreturnsundefinedwhen root is not set; skip SCM/ClientManager recreation when they already existsrc/collaboration/clientManager.tsreconnect()method to re-register handlers on new socket; save handlers as named object; guardremovePositioninupdateStatusforEachsrc/api/socketio.ts.once()forconnectionRejected; dispose previousEventBuslistener before re-registering; log errors instead of throwingTest plan
MaxListenersExceededWarningandEntryNotFounderrors