fix(viewer): singleton guard prevents port drift on reactivation#1453
Open
kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
Open
fix(viewer): singleton guard prevents port drift on reactivation#1453kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
Conversation
When the host gateway restarts and re-calls activate(), the previous ViewerServer instance may still hold the port. Without cleanup, the new instance hits EADDRINUSE and drifts to 18800+, causing Memory unavailable. - Add module-level singleton tracking for ViewerServer - Stop previous viewer instance before creating new one in activate() - Ensure server.stop() fully releases the HTTP port Fixes MemTensor#1430
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 #1430 — viewer self-starts repeatedly under host lifecycle mismatch, causing port drift (18799→18800+) and "Memory unavailable".
Root Cause
When the gateway restarts or reloads,
register()is called again. Each call creates a newViewerServerinstance, but the previous one may still hold the port. The new instance hitsEADDRINUSEand falls back to port+1, eventually drifting away from the expected 18799.Fix
register()scopestop()the previous viewer/hub andclose()the previous store before creating new onesViewerServer.stop()now returns aPromise<void>that resolves only afterserver.close()callback fires, ensuring the port is fully releasedScope
This PR addresses the plugin side of the lifecycle mismatch. The host-side gap (deferred
service.start()call path) would need a separate OpenClaw upstream fix.Testing
npm run buildpasses