Skip to content

fix: #4125 return unread unbatcher writers to the pool on disconnect - #4132

Merged
miwarnec merged 1 commit into
MirrorNetworking:masterfrom
armadavalor:fix/4125-unbatcher-writer-leak
Nov 6, 2026
Merged

miwarnec merged 1 commit into
MirrorNetworking:masterfrom
armadavalor:fix/4125-unbatcher-writer-leak

Conversation

@armadavalor

@armadavalor armadavalor commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Unread batches queued in an Unbatcher hold pooled NetworkWriterPooled instances. They were never returned when the connection went away, so the pool lost one writer (with its expanded buffer) per such disconnect.

Server: NetworkConnection.Cleanup() only cleared the send-side batchers. NetworkConnectionToClient now overrides Cleanup() and clears unbatcher. OnTransportDisconnected always calls Cleanup(), so this also covers the UnpackAndInvoke failure path, which calls Disconnect() and returns without clearing.

Client: NetworkClient.Initialize() and Shutdown() replaced unbatcher with a new instance and dropped the old queue. They now call Clear() first.

Verification: I added Cleanup_ClearsUnbatcher to NetworkConnectionToClientTests. I could not run it because I have no Unity Editor here, so this is untested in Unity. The change is three Clear() calls on an existing method, and the diff is 25 added lines.

Closes #4125

@miwarnec
miwarnec merged commit b37372b into MirrorNetworking:master Nov 6, 2026
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

Successfully merging this pull request may close these issues.

Bug Report: Unbatcher pooled writers leak on disconnect paths (UnpackAndInvoke failure / Cleanup)

2 participants