Skip to content

[FLINK-31244][core] Capture expected IllegalStateException on concurrent free in OffHeapUnsafeMemorySegmentTest#28359

Open
sherry255 wants to merge 1 commit into
apache:masterfrom
sherry255:FLINK-31244-test-concurrent-free
Open

[FLINK-31244][core] Capture expected IllegalStateException on concurrent free in OffHeapUnsafeMemorySegmentTest#28359
sherry255 wants to merge 1 commit into
apache:masterfrom
sherry255:FLINK-31244-test-concurrent-free

Conversation

@sherry255

Copy link
Copy Markdown

What is the purpose of the change

Fixes FLINK-31244. OffHeapUnsafeMemorySegmentTest.testCallCleanerOnceOnConcurrentFree
starts two threads that both call segment.free() on the same MemorySegment to
verify the cleaner runs exactly once. When the multiple-free check is enabled
(-Dflink.tests.check-segment-multiple-free, which is set in CI), the thread that
loses the race throws IllegalStateException("MemorySegment can be freed only once!").
Because free() was used directly as the thread body, that expected exception was
raised as an uncaught exception in the worker thread and printed to the CI logs as
noise, e.g.:

Exception in thread "Thread-13" java.lang.IllegalStateException: MemorySegment can be freed only once!

The test still passed; only the logs were polluted.

Brief change log

  • Wrap the concurrent segment.free() call in a Runnable that catches the expected
    IllegalStateException, so it is no longer surfaced as an uncaught exception. The
    existing assertion that the cleaner ran exactly once is unchanged.

Verifying this change

This change is a test-only fix and can be verified as follows:

  • Before: running OffHeapUnsafeMemorySegmentTest#testCallCleanerOnceOnConcurrentFree
    with -Dflink.tests.check-segment-multiple-free passes but prints
    Exception in thread "Thread-N" java.lang.IllegalStateException: MemorySegment can be freed only once!.
  • After: the same run passes with no such exception printed.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? no

@flinkbot

flinkbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

…ent free in OffHeapUnsafeMemorySegmentTest

When two threads free the same MemorySegment concurrently and the multiple-free
check is enabled (flink.tests.check-segment-multiple-free, set in CI), the thread
that loses the race throws an IllegalStateException. Because free() was used
directly as the thread body, that expected exception surfaced as an uncaught
exception and polluted the CI logs. Wrap the free() call so the expected
exception is captured; the test still asserts the cleaner runs exactly once.
@sherry255 sherry255 force-pushed the FLINK-31244-test-concurrent-free branch from 2a635f4 to 1f6c607 Compare June 8, 2026 15:15
try {
segment.free();
} catch (IllegalStateException e) {
// On concurrent free() the thread that loses the race observes the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: adding these comments to the flink code for each debug could make the code lengthy. Can you shorten it? Reference to jira and detail debug could be reduced.

@MartijnVisser

Copy link
Copy Markdown
Contributor

Also make sure that you're following the AI guidelines

@github-actions github-actions Bot added the community-reviewed PR has been reviewed by the community. label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants