ffang commented on PR #3734:
URL: https://github.com/apache/cxf/pull/3734#issuecomment-6960601907

   > A few concerns before merging:
   > 
   > **1. The propagate=true path is still racy.** 
`incomingObserver.onMessage(inMessage)` is called after the `synchronized 
(exchange)` block has been left, so the `FINISHED` check doesn't cover it:
   > 
   > 1. The ack thread passes the check (not finished yet) and releases the 
lock.
   > 2. The decoupled reply finishes: `FINISHED=TRUE`, `inMessage=reply`.
   > 3. The ack thread calls `incomingObserver.onMessage(empty 202)`, and 
`ClientImpl.onMessage` sets `exchange.setInMessage(...)` with no lock held 
(ClientImpl.java:843), then sets it again in its `finally` block (line 970).
   > 
   > The client ends up with the empty message, which is CXF-9275 again. I 
think the check belongs in `ClientImpl.onMessage` itself, under the same lock 
as its `finally` block. An empty 202 for an exchange that is already `FINISHED` 
would be dropped there. That would cover both propagate settings and keep 
`HTTPConduit` from depending on `ClientImpl.FINISHED`, which the JAX-RS client 
never sets anyway.
   > 
   > **2. The ignored 202 still changes the exchange.** 
`doProcessResponseCode()` puts `RESPONSE_CODE=202` (and possibly 
`service_not_available`) on the exchange before the new check. After a reply 
has finished, the late 202 still overwrites the response code, and 
`ClientImpl.doInvoke` copies it into the response context as 
`HTTP_RESPONSE_CODE`. Also, `FINISHED` is set only at the end of 
`ClientImpl.onMessage`. While the reply is still in its interceptor chain, the 
202 passes the check and briefly replaces `exchange.getInMessage()`.
   > 
   > **3. The concurrent tests look flaky.**
   > 
   > * `testConcurrentReplyAndAcknowledgement` ends with 
`assertReplyPreserved()`, which requires `IN_CHAIN_COMPLETE == null` and no 
observed messages. That only holds if the reply wins the race. When the ack 
thread takes the lock first, the test fails even though the reply was kept. The 
assertion should only check that the reply survived.
   > * With `propagate=true`, the 500-iteration test can catch the race in (1), 
because the test observer calls `setInMessage` outside the lock.
   > * The test observer only calls `setInMessage`. It doesn't set `FINISHED` 
or call `notifyAll` the way `ClientImpl.onMessage` does, so the propagate=true 
/ ack-first case isn't really exercised.
   > 
   > **Minor:** the flag is now set while holding the lock, so adding 
`exchange.notifyAll()` after `exchange.put("IN_CHAIN_COMPLETE", ...)` would 
cost nothing. It would wake anything waiting on that flag (e.g. 
`AbstractClient` around line 647) straight away, not when its timeout ends.
   
   Thanks @coheigea, I went through each point.
   
   **1. propagate=true.** The race is real, but this path doesn't work with a 
decoupled endpoint at all. `propagate202Response` is only set by the JAX-RS 
client (`AbstractClient.setSupportOnewayResponseProperty`), which has no 
decoupled endpoint. I tried it on a decoupled JAX-WS call in `MAPTest`: every 
call fails with "Can't find input stream in message", with or without this PR, 
because `ClientImpl.onMessage` runs the SOAP chain on the empty 202. So that 
race can't affect anyone today.
   
   The check can't move to `ClientImpl.onMessage` either. With the default 
`propagate202Response=false`, the 202 never reaches `ClientImpl`, because 
`HTTPConduit` updates the exchange itself. That's the CXF-9275 case, so the 
check has to be in `HTTPConduit`. For the JAX-RS client, `FINISHED` is never 
set, so the check does nothing there, just as before.
   
   **2. The exchange after an ignored 202.**
   - `RESPONSE_CODE`: the decoupled reply never sets a response code, so a 
decoupled client always gets the 202 in `HTTP_RESPONSE_CODE`, whichever arrives 
first. I checked it in `MAPTest`: 202 on every call. The late 202 writes the 
same value.
   - While the reply is still in its chain: yes, the 202 can still replace the 
in message for a moment, as it could before. For sync calls it does no harm, 
because `ClientImpl.onMessage` puts the reply back in its `finally` block, 
under the lock, before the waiting thread reads it. For async calls, 
`processResult` reads `exchange.getInMessage()`, so there's a narrow window 
left. Closing it means changing how `ClientImpl` publishes the reply, which I'd 
rather do separately than grow this PR.
   
   **3. Tests.** Agreed, thanks. In 732b5ab69c:
   - the single concurrent test is gone and the 500-iteration one takes its 
name;
   - it only asserts that the reply survives and that `FINISHED` is set, 
whichever thread wins;
   - it's skipped with propagate=true, per point 1.
   
   It passed 30 runs out of 30 locally.
   
   **Minor:** added `exchange.notifyAll()` after setting `IN_CHAIN_COMPLETE`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to