gravitino icon indicating copy to clipboard operation
gravitino copied to clipboard

[CORE] Fix race condition in AuthorizationRequestContext.loadRole()

Open HarshMehta112 opened this issue 1 month ago • 1 comments

Fixed #9084

  • Replaced separate hasLoadRole.get() and hasLoadRole.set(true) calls with an atomic
    hasLoadRole.compareAndSet(false, true) operation.

  • This makes the check-and-set atomic, ensuring the runnable executes only once,
    even under concurrent invocations.

  • Previously, multiple threads could see false and execute the runnable simultaneously,
    causing duplicate executions.

  • Added a new unit test: testLoadRoleRunsOnceEvenWhenInvokedConcurrently.

  • Verified that the runnable executes only once, even when loadRole() is called concurrently.

Result

Improved thread-safety of loadRole() and prevented race conditions during concurrent access.

HarshMehta112 avatar Nov 12 '25 04:11 HarshMehta112

Please see the conversation in #9084. While this does fix the race condition it introduces some other issues and I think a little more needs to be done here.

justinmclean avatar Nov 12 '25 23:11 justinmclean