Skip to content

Use notifyAll in IOTaskRunnable.kick (CodeQL java/notify-instead-of-notify-all)#243

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-notify-all
Jul 16, 2026
Merged

Use notifyAll in IOTaskRunnable.kick (CodeQL java/notify-instead-of-notify-all)#243
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-notify-all

Conversation

@vharseko

@vharseko vharseko commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Resolves the java/notify-instead-of-notify-all alert in IOTaskRunnable.

kick() woke a blocked worker with notify():

synchronized void kick() {
    if (!_notified) {
        _notified = true;
        notify();
    }
}

Each IOTaskRunnable has exactly one background thread (created in start()),
and that thread is the only one that ever calls wait() on the monitor (in
run()), so notify() and notifyAll() are functionally equivalent today.
However, notify() is fragile — if any other thread ever waited on the same
monitor, it could wake the wrong one and leave the worker blocked.

Fix

Use notifyAll(). With a single waiter it wakes exactly the same thread (no
thundering herd), and the wait loop already re-checks its guards
(shouldStop() / _notified / recomputed wait time), so additional wake-ups are
handled correctly.

Testing

mvn -o -pl persistit/core compile — BUILD SUCCESS.

@vharseko
vharseko requested a review from maximthomas July 8, 2026 14:42
@vharseko vharseko added bug codeql CodeQL static-analysis findings labels Jul 8, 2026
…otify-all)

kick() woke a waiter with notify(). Today there is only ever a single waiter -
the one background thread per IOTaskRunnable that blocks in run()'s wait() - so
notify() and notifyAll() are equivalent, but notify() is fragile: if another
thread ever waited on the same monitor, notify() could wake the wrong one.

Switch to notifyAll(). It wakes the same single waiter now (no thundering herd),
and the wait loop already re-checks its conditions (shouldStop / _notified /
recomputed wait time), so any extra wake-ups are handled safely.
@vharseko
vharseko force-pushed the features/codeql-notify-all branch from 7433a4a to 73f26e1 Compare July 16, 2026 17:10
@vharseko
vharseko merged commit 5f436d0 into OpenIdentityPlatform:master Jul 16, 2026
4 of 13 checks passed
@vharseko
vharseko deleted the features/codeql-notify-all branch July 16, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug codeql CodeQL static-analysis findings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants