Add disposal method to SerializedStateManager for snapshot refresh timer cleanup#25200
Add disposal method to SerializedStateManager for snapshot refresh timer cleanup#25200RishhiB wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…mer cleanup - Added dispose() method to SerializedStateManager to clear the refresh timer - Called serializedStateManager.dispose() in Container.disposeCore() for complete cleanup - Prevents Node.js processes from hanging due to long-running snapshot refresh timers
There was a problem hiding this comment.
Pull Request Overview
This PR adds proper disposal functionality to the SerializedStateManager to prevent Node.js processes from hanging due to undisposed timers. The change addresses a resource cleanup issue where a 24-hour snapshot refresh timer was not being properly disposed of when containers are destroyed.
- Added a
dispose()method toSerializedStateManagerthat clears the refresh timer - Integrated the disposal call into the container's cleanup lifecycle via
Container.disposeCore()
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/loader/container-loader/src/serializedStateManager.ts | Adds dispose method to clear the refresh timer |
| packages/loader/container-loader/src/container.ts | Calls serializedStateManager.dispose() during container disposal |
| * This prevents Node.js processes from hanging due to the refresh timer. | ||
| */ | ||
| public dispose(): void { | ||
| this.refreshTimer.clear(); |
There was a problem hiding this comment.
The dispose method should check if refreshTimer exists before calling clear() to avoid potential runtime errors if dispose() is called multiple times or if the timer was never initialized.
| this.refreshTimer.clear(); | |
| if (this.refreshTimer) { | |
| this.refreshTimer.clear(); | |
| } |
|
This PR has been automatically marked as stale because it has had no activity for 60 days. It will be closed if no further activity occurs within 8 days of this comment. Thank you for your contributions to Fluid Framework! |
SerializedStateManagercreates a 24-hour snapshot refresh timer (refreshTimer) but provides no mechanism to dispose of it. This could potentially cause Node.js processes to hang in scenarios where the timer outlives the container lifecycle.Root Cause
The
SerializedStateManagerclass instantiates aTimerobject with a 24-hour timeout (line 153:60 * 60 * 24 * 1000) for periodic snapshot refreshing. While this timer is started and restarted throughout the container lifecycle, there is no corresponding disposal method to clear it when the container is disposed.Solution
dispose()method toSerializedStateManagerto clear the refresh timerserializedStateManager.dispose()inContainer.disposeCore()AB#46301