fix(watch): do not drop events when a read carries multiple responses#224
fix(watch): do not drop events when a read carries multiple responses#224AlinsRan wants to merge 1 commit into
Conversation
read_watch() splits one body read into several watch responses, decodes the events of each of them into all_events, and then attaches all_events to `body`, which points at the last decoded response. The attach was guarded by `#all_events > 1`, so a read holding [response with 1 event, response without events] returned the last response as is and the event was lost, silently and unrecoverably for the caller. Today etcd never produces that layout because the only event-less responses are `created` and `canceled`, which never trail an event response. It does as soon as the watch is created with progress_notify, which apache/apisix needs to advance start_revision safely (apache/apisix#13067). Attach the events whenever any were collected. Also guard on body.result, which is nil when the last response is an error body with an http code below 500 - reachable before this change too, and a nil index in the watch loop.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Problem
read_watch()splits one body read into several watch responses, decodes the events of each intoall_events, and then attachesall_eventstobody— which points at the last decoded response. The attach was guarded by#all_events > 1:So a read holding
[response with 1 event, response without events]returns the last response as is, and the event is silently lost. The caller cannot detect it.Today etcd never produces that layout, because the only event-less responses are
createdandcanceledand neither trails an event response. It does as soon as the watch is created withprogress_notify: a notification can be coalesced right behind an event response on the same TCP read.apache/apisix needs
progress_notifyto advancestart_revisionsafely (apache/apisix#13067), so this has to be fixed first — otherwise the same class of silent event loss is reintroduced inside the library.Fix
Attach the events whenever any were collected (
> 0).Also guard on
body.result, which isnilwhen the last response is an error body with an http code below 500. That path is reachable today too and> 1would already indexnilthere, so this is a strict improvement rather than a new behaviour.Compatibility
No behaviour change for anything that exists today:
#chunks == 1returns early for event-less responses)[notify, event response]order:bodyalready is the event response, so the assignment is a no-op[event, canceled]: both spellings end in the samecompactedfull-reload path on the apisix sideTest
t/v3/watch.tdrives the client against a fake watch endpoint that writes an event response followed by a progress notification in a single body chunk, and asserts the event survives. A real etcd cannot be pushed into producing that coalescing reliably.Not run locally — CI covers it.
Follow-up
A
v1.10.7release is needed before apache/apisix can pin it and merge its side.