Skip to content

Commit e832422

Browse files
committed
Make Binder transport triggerEvent thread-safe and guarantee ordering.
Updated ServerInbound.triggerEvent to invoke the listener's triggerEvent callback inside the synchronized(this) block. This ensures that the check for isClosed() and the invocation of the listener are atomic relative to stream closure (which also runs under the same lock). This prevents a race where triggerEvent could be called on the listener after the stream has been closed, which would result in out-of-order events delivered to the application. This is consistent with how other listener callbacks (like closed and halfClosed) are delivered in Inbound.java. TAG=agy CONV=e1bfa5a2-e855-4f79-abdd-ef2b264977be
1 parent b9e1e2b commit e832422

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

binder/src/main/java/io/grpc/binder/internal/Inbound.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,13 @@ protected void deliverCloseAbnormal(Status status) {
669669
}
670670

671671
void triggerEvent(Object event) {
672-
ServerStreamListener localListener;
673672
synchronized (this) {
674673
if (isClosed()) {
675674
return;
676675
}
677-
localListener = listener;
678-
}
679-
if (localListener != null) {
680-
localListener.triggerEvent(event);
676+
if (listener != null) {
677+
listener.triggerEvent(event);
678+
}
681679
}
682680
}
683681

0 commit comments

Comments
 (0)