Skip to content

Commit b7eaab4

Browse files
committed
Handle very early completion notification
On a Servlet container a completion notification may come at any time even in the UNSUBSCRIBED state, i.e. before the write Publisher has called onSubscribe. See: gh-23553
1 parent 07b0fa1 commit b7eaab4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ public <T> void onSubscribe(AbstractListenerWriteFlushProcessor<T> processor, Su
246246
super.onSubscribe(processor, subscription);
247247
}
248248
}
249+
250+
@Override
251+
public <T> void onComplete(AbstractListenerWriteFlushProcessor<T> processor) {
252+
// This can happen on (very early) completion notification from container..
253+
if (processor.changeState(this, COMPLETED)) {
254+
processor.resultPublisher.publishComplete();
255+
}
256+
else {
257+
processor.state.get().onComplete(processor);
258+
}
259+
}
249260
},
250261

251262
REQUESTED {

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ public <T> void onSubscribe(AbstractListenerWriteProcessor<T> processor, Subscri
322322
super.onSubscribe(processor, subscription);
323323
}
324324
}
325+
326+
@Override
327+
public <T> void onComplete(AbstractListenerWriteProcessor<T> processor) {
328+
// This can happen on (very early) completion notification from container..
329+
processor.changeStateToComplete(this);
330+
}
325331
},
326332

327333
REQUESTED {

0 commit comments

Comments
 (0)