Vyacheslav Koptilin created IGNITE-28386:
--------------------------------------------
Summary: Lazy<T> fast path does not safely publish the initialized
value
Key: IGNITE-28386
URL: https://issues.apache.org/jira/browse/IGNITE-28386
Project: Ignite
Issue Type: Bug
Reporter: Vyacheslav Koptilin
Assignee: Vyacheslav Koptilin
Lazy<T>
(modules/core/src/main/java/org/apache/ignite/internal/util/Lazy.java) uses
double-checked
locking with the intent of piggybacking visibility of the non-volatile field
val on the volatile
field supplier. This technique is valid only if the volatile read is
performed before the
non-volatile read. The current implementation violates this ordering.
In get(), val is read first (line 50) without any volatile access preceding
it:
{code:java}
T v = val; // non-volatile read — no happens-before established
if (v == null) {
if (supplier != EMPTY) { // volatile read — only reached when val is
null {code}
When val is non-null, the fast path returns immediately and never reads
supplier. This means there is no happens-before relationship between the
writing thread's store to val and the reading thread's load of val. This is a
data race: a reading thread may observe a non-null reference in val while the
object it points to is not fully initialized (some field writes performed
inside supplier.get() may not yet be visible).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)