From 06b2ab39088f128d3aa5ca355d0bc0f2c7b36ab3 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 21 Nov 2017 22:57:15 -0500 Subject: [PATCH] Use volatile for subscriber in base publishers Issue: SPR-16207 --- .../reactive/AbstractListenerReadPublisher.java | 12 ++++++------ .../http/server/reactive/WriteResultPublisher.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java index c707f4865e..29e7a202fc 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java @@ -52,17 +52,17 @@ public abstract class AbstractListenerReadPublisher implements Publisher { private volatile long demand; - private volatile boolean completionBeforeDemand; - - @Nullable - private volatile Throwable errorBeforeDemand; - @SuppressWarnings("rawtypes") private static final AtomicLongFieldUpdater DEMAND_FIELD_UPDATER = AtomicLongFieldUpdater.newUpdater(AbstractListenerReadPublisher.class, "demand"); @Nullable - private Subscriber subscriber; + private volatile Subscriber subscriber; + + private volatile boolean completionBeforeDemand; + + @Nullable + private volatile Throwable errorBeforeDemand; // Publisher implementation... diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java index 1d3dab4a74..189d342889 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java @@ -43,7 +43,7 @@ class WriteResultPublisher implements Publisher { private final AtomicReference state = new AtomicReference<>(State.UNSUBSCRIBED); @Nullable - private Subscriber subscriber; + private volatile Subscriber subscriber; private volatile boolean completedBeforeSubscribed;