JakeChampion opened a new pull request, #13971:
URL: https://github.com/apache/trafficserver/pull/13971

   ## Problem
   
   With compress.so `cache true`, a request that accepts `br` or `gzip` can hit 
an uncompressed cached object. Then these steps occur:
   
   1. The compress transform reads the cached body.
   2. `HttpSM` opens a cache write for the transformed copy 
(`CACHE_ISSUE_WRITE_TRANSFORM`).
   3. When several requests do this at the same time, that open write retries 
on the write lock.
   4. If the cache-to-transform tunnel completes during the retry, 
`HTTP_TUNNEL_EVENT_DONE` arrives in `HttpSM::state_cache_open_write`.
   
   `state_cache_open_write` assigns `pending_action` (the result of 
`adjust_thread`, and then `nullptr`) before it examines the event. An 
assignment to a `PendingAction` cancels the action that it holds. Here that 
action is the pending open write of `transform_cache_sm`, so `HttpCacheSM` 
drops the open write callback.
   
   The tunnel event goes to `state_common_wait_for_transform_read`. That state 
waits for `TRANSFORM_READ_READY`, but this event occurred before the cache 
write started. Nothing resumes the transaction. It does not send a response 
byte, and it stays open until the client closes the connection.
   
   The slow log shows this signature for a stalled transaction:
   
   ```
   status: 200 ... server state: 0 ... cache_open_write_begin: -0.001 
cache_open_write_end: 0.03
   server_connect: -0.001 ... ua_write: -0.001 ... bytes: 0
   ```
   
   `cache_open_write_end` has a value because the tunnel event, not the cache, 
entered `state_cache_open_write`.
   
   ## Fix
   
   Handle `HTTP_TUNNEL_EVENT_DONE` at the start of `state_cache_open_write`, 
before the code that touches `pending_action`. The open write stays pending, so 
its callback continues the transaction as usual. The old `case 
HTTP_TUNNEL_EVENT_DONE` in the switch is now unreachable, so this change 
removes it.
   
   The event is forwarded to the same function as before, 
`state_common_wait_for_transform_read`. Other `HttpSM` states that receive 
`HTTP_TUNNEL_EVENT_DONE` from `HttpTunnel` also do not adjust the thread. Only 
cache callbacks need `adjust_thread`.
   
   ## Testing
   
   `test_compress_transform_cache_write.py` does these steps:
   
   1. It stores a 2 MB uncompressed JSON object.
   2. It sends 6 concurrent `br` requests for that object.
   3. It repeats this for 10 objects.
   
   It uses `open_read_retry_time: 100` so that the open write retries for long 
enough. Each request must complete with a 200 and `Content-Encoding: br`. If 
compress.so has no brotli support, the test is skipped.
   
   I reproduced the problem first with a 10.2.0 build, a small origin and curl. 
The settings were `cache true` and `open_read_retry_time: 100`.
   
   | Build | Concurrent `br` requests after a cache fill | Stalled |
   |---|---|---|
   | 10.2.0 | 180 | 130 |
   | 10.2.0 with this change | 180 + 320, then 180 `gzip` and 50 sequential | 0 
|
   
   For the stalled transactions, 
`proxy.process.http.current_client_transactions` stayed at the stall count 
after all clients closed. With the fix, it went back to 0. The compressed copy 
is stored, and repeat requests get byte-identical bodies.
   
   The change applies to `master` with only a line offset. My local container 
stopped working before I could run the new Uranium test on `master`, so CI will 
be its first run. I will report the result here.
   
   This also affects 10.2.x. A backport to 10.2.x would be useful.
   


-- 
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