Skip to content

Commit c1ee7d3

Browse files
Clarify synchronized(context)
1 parent d02f655 commit c1ee7d3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/FilterableClientToClient.java

+5
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ private static Single<StreamingHttpResponse> executeRequest(final StreamingHttpR
221221
// chain and accidentally subscribed to the same request concurrently. This protection helps them avoid
222222
// ambiguous runtime behavior caused by a corrupted mutable request state.
223223
final Object inFlight;
224+
// Note that because request.context() lazily allocates a new ContextMap, there is a risk that
225+
// synchronization will happen on two different contexts. However, this is acceptable compromise because:
226+
// - Most likely users subscribe 2+ times to the same request from the same thread.
227+
// - This is the best effort protection, giving users at least one rejection should be enough to let them
228+
// know their code is incorrect and should be rewritten.
224229
synchronized (context) {
225230
// We do not override lock because other layers may already set their own one.
226231
inFlight = context.putIfAbsent(HTTP_IN_FLIGHT_REQUEST, lock);

0 commit comments

Comments
 (0)