Skip to content

Commit 84aeaab

Browse files
committed
add synchronization around asynContext to avoid onTimeout race condition
1 parent f4f0a10 commit 84aeaab

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/main/groovy/org/grails/plugins/rx/web/RxResultSubscriber.groovy

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ class RxResultSubscriber extends Subscriber implements AsyncListener {
105105

106106
@Override
107107
void onNext(Object o) {
108-
if(asyncComplete) {
109-
if( !isUnsubscribed() ) {
110-
unsubscribe()
108+
synchronized (asyncContext) {
109+
if(asyncComplete) {
110+
if( !isUnsubscribed() ) {
111+
unsubscribe()
112+
}
113+
return
111114
}
112-
return
113115
}
114116

115117
if(o instanceof RxResult) {
@@ -252,27 +254,34 @@ class RxResultSubscriber extends Subscriber implements AsyncListener {
252254

253255
@Override
254256
void onComplete(AsyncEvent event) throws IOException {
255-
asyncComplete = true
256-
if(!isUnsubscribed()) {
257-
unsubscribe()
257+
synchronized (asyncContext) {
258+
asyncComplete = true
259+
if(!isUnsubscribed()) {
260+
unsubscribe()
261+
}
258262
}
259263
}
260264

261265
@Override
262266
void onTimeout(AsyncEvent event) throws IOException {
263-
if(!isUnsubscribed()) {
264-
unsubscribe()
265-
onError(event.throwable)
266-
asyncComplete = true
267+
synchronized (asyncContext) {
268+
269+
if(!isUnsubscribed()) {
270+
unsubscribe()
271+
onError(event.throwable)
272+
asyncComplete = true
273+
}
267274
}
268275
}
269276

270277
@Override
271278
void onError(AsyncEvent event) throws IOException {
272-
if(!isUnsubscribed()) {
273-
unsubscribe()
274-
onError(event.throwable)
275-
asyncComplete = true
279+
synchronized (asyncContext) {
280+
if(!isUnsubscribed()) {
281+
unsubscribe()
282+
onError(event.throwable)
283+
asyncComplete = true
284+
}
276285
}
277286
}
278287

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy