Skip to content

ExternalizableBean: do not retain oversized thread-local buffer after write - #52

Merged
kelunik merged 1 commit into
masterfrom
fix/release-large-externalization-buffer
Nov 4, 2026
Merged

kelunik merged 1 commit into
masterfrom
fix/release-large-externalization-buffer

Conversation

@kelunik

@kelunik kelunik commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

The thread-local BytesCache only shrank at the start of the next dynamic field write, so an idle thread kept a very large buffer indefinitely.

Reset the buffer right after each dynamic field is written; reset() drops the backing array if its capacity exceeds BYTES_CACHE_MAX_RETAINED_CAPACITY (1 MB). If a field fails to write, the thread-local StreamCache is replaced by a fresh one, since its ObjectOutput may hold partial state.

Add tests for the retention behavior (including worker threads, nested beans, failed writes and the capacity boundary) and a manual multi-threaded stress tester, ExternalizationBufferStressTester.

… write

The thread-local BytesCache only shrank at the start of the next dynamic
field write, so an idle thread kept a very large buffer indefinitely.

Reset the buffer right after each dynamic field is written; reset() drops
the backing array if its capacity exceeds BYTES_CACHE_MAX_RETAINED_CAPACITY
(1 MB). If a field fails to write, the thread-local StreamCache is replaced
by a fresh one, since its ObjectOutput may hold partial state.

Add tests for the retention behavior (including worker threads, nested
beans, failed writes and the capacity boundary) and a manual multi-threaded
stress tester, ExternalizationBufferStressTester.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kelunik
kelunik merged commit 8ae5db3 into master Nov 4, 2026
1 check passed
@kelunik
kelunik deleted the fix/release-large-externalization-buffer branch November 4, 2026 13:44
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.

2 participants