Skip to content

FELIX-6880: Sort a copy of the service property array in MultiPropertyFilterIndex - #599

Merged
paulrutter merged 1 commit into
apache:masterfrom
paulrutter:maintenance/FELIX-6880-sort-copy
Nov 25, 2026
Merged

paulrutter merged 1 commit into
apache:masterfrom
paulrutter:maintenance/FELIX-6880-sort-copy

Conversation

@paulrutter

@paulrutter paulrutter commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/FELIX-6880

Problem

MultiPropertyFilterIndex.getPermutations sorts the array it receives, in place. For the objectClass property this array is the live array of the service registration. The framework returns it without a copy. Adapter components also share one array between all their children. If threads start services in parallel, they can sort the same array at the same time. A concurrent sort can duplicate one name and lose another, so the index files the service under a wrong key.

Fix

getPermutations now sorts a copy of the array (clone()).

Test

New test objectClassArrayOfReferenceIsNotModified in MultiPropertyFilterIndexReferencedTest. It checks that the array of the service reference is unchanged after addedService.

  • Without the fix: the test fails.
  • With the fix: all 8 tests in the class pass.

What is proven and what is not

Proven:

  • The in-place sort of a shared array.
  • A plain Java test with two threads sorting the same unsorted 4-name array (300000 rounds) corrupted 2 arrays.
  • The new unit test fails without the fix and passes with it.

Not proven:

  • That this race caused a startup stall that was seen once in about 150 runs of parallel startup. It is a possible cause, but this is not confirmed.

createKeys also sorts the property keys in place. That is safe today because the framework returns a copy of the keys, so it is not changed here.

🤖 Generated with Claude Code

…yFilterIndex

getPermutations sorted the array it received. For the objectClass property
that array is the live array of the service registration. Adapter components
also share one such array between all children. Threads that start services
in parallel can sort it at the same time. A concurrent sort can duplicate one
name and lose another, so the index files the service under a wrong key.

Sort a copy instead. Add a test that checks the array of the service
reference stays unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvNRqvkmhBx6EjmxH35aB4
@paulrutter
paulrutter requested a review from pderop November 23, 2026 19:55
@paulrutter

paulrutter commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@pderop This is the PR for the second race. I'm still running tests against it (including your PR) to see if it's actually fixed now.
Currently at 200 application starts in a loop without observing any stalls or exceptions, i'll let it run up to 500 as this second race only reproduced 4 out of 500 times.

@pderop

pderop commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

yesterday, I was busy, but I'll review today.

thanks Paul!

@pderop pderop left a comment

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.

good catch Paul, LGTM.

@paulrutter

Copy link
Copy Markdown
Contributor Author

good catch Paul, LGTM.

Thanks! My test finished, 500 runs, no exceptions and no stalls 🎉

@paulrutter
paulrutter merged commit 4b3d7c0 into apache:master Nov 25, 2026
4 checks passed
@paulrutter
paulrutter deleted the maintenance/FELIX-6880-sort-copy branch November 25, 2026 05:51
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.

3 participants