Experimentation events are dropped when they're tracked faster than one batch round-trip, and the buffer can't be raised past Flagsmith's 2 MiB batch limit
Maintainer thường phản hồi trong vòng 2 ngày
@tharunkumardeveloper đang làm issue này rồi.
Từ ngày 26/11/2026.
- #331 của @tharunkumardeveloper — đang mở
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
Hướng nghiên cứu
Start with build/cjs/sdk/events.js at the buffer overflow, batch creation, and non-retryable response handling points cited in the issue. Reproduce the loss with the linked repro.mjs against its delayed local endpoint, then trace the corresponding TypeScript source and event processor tests. Done means the chosen behavior prevents or reports dropped events, including when a batch exceeds the server's 2 MiB limit.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
With enableEvents: true, @flagsmith/nodejs 9.4.0 sends its whole event buffer as one batch and keeps one batch in flight at a time. While that batch is in flight, a full buffer drops its oldest event for each new one. This is documented (build/cjs/sdk/events.js:41-44) and each drop is logged as a warning, but:
- The app gets no programmatic signal. Nothing is returned, emitted or counted, so code that records "events sent" sees no loss unless it parses log messages.
- Raising
maxBufferdoesn't fix it, and can make it worse. Batches are never split, and Flagsmith rejects a request body over 2 MiB (api/experimentation/constants.py,MAX_BODY_BYTES = 2_097_152in 2.291.0) with a 413. The SDK then drops the whole batch. A buffer over roughly 7,000–11,000 events (depending on event size) can produce batches that are refused whole.
So for any app whose event rate × the time one batch takes to post is more than maxBuffer, a share of experiment events is lost, and the experiment results computed from them are biased toward whichever events survived.
Reproduction
No Flagsmith instance is needed: repro.mjs (~90 lines, raw results in results.jsonl) runs the real SDK against a local stand-in for the events endpoint that answers like 2.291.0 (202 { accepted, rejected }, 413 over 2 MiB) after a set delay. It tracks events at a fixed rate and compares how many were tracked with how many the endpoint received.
npm i @flagsmith/[email protected]
node repro.mjs <eventsPerSecond> <seconds> <endpointDelayMs> [maxBuffer] [flushIntervalMs]
Results (Node 24, Windows 11; @flagsmith/nodejs 9.4.0)
| SDK settings | Events/s | Endpoint answers after | Tracked | Received | Lost | Logged as dropped |
|---|---|---|---|---|---|---|
| defaults (buffer 1,000, flush 10 s) | 100 | 0.2 s | 6,000 | 6,000 | 0 | 0 |
| defaults | 300 | 5 s | 9,000 | 6,447 | 2,553 (28.4%) | 2,553 |
| defaults | 150 | 10 s | 9,000 | 6,470 | 2,530 (28.1%) | 2,530 |
maxBuffer: 7000, flushInterval: 1000 |
700 | 4 s | 21,000 | 21,000 | 0 | 0 |
maxBuffer: 7000, flushInterval: 1000 |
700 | 20 s | 21,000 | 13,960 | 7,040 (33.5%) | 7,040 |
maxBuffer: 20000, flushInterval: 1000 |
700 | 30 s | 28,000 | 2,091 | 25,909 (92.5%) | 8,000 + 2 batches refused with 413 |
The delays are deliberately long here, to make the effect easy to see. Against a real self-hosted Flagsmith 2.291.0 on a 2-vCPU VM, I measured batch round-trips of 4 to 10.7 s under load (~700 events/s from one Node process), and lost 2.2% of events in one run with maxBuffer: 6000 and flushInterval: 2000.
Still there in 9.5.0
Re-run on @flagsmith/nodejs 9.5.0 (the latest, released 23 Nov), same machine, defaults, 300 events/s for 20 s, endpoint answering after 5 s: 6,000 tracked, 4,476 received, 1,524 lost (25.4%), all 1,524 logged as dropped. On 9.4.0 with the same settings: 1,527 lost (25.4%). repro.mjs prints the version it actually ran.
Where it happens
build/cjs/sdk/events.js:239: a full buffer while a batch is in flight drops its oldest event.build/cjs/sdk/events.js:260: the whole buffer becomes one batch, with no size cap.build/cjs/sdk/events.js:362: a non-retryable status (413 included) drops the whole batch.
Suggestions (any one helps)
- Split a flush into batches under the server's body limit (by bytes, e.g. ≤ 1.5 MiB), so
maxBuffercan be raised safely. - Expose drops programmatically, for example an
onEventsDropped(count, reason)callback ineventProcessorConfigor a counter on the client, so apps can alert on loss. - Optionally allow more than one batch in flight, or flush as soon as the buffer reaches a high-water mark rather than only on the interval.
Workaround I use
In the meantime, the app can hold its own trackEvent calls back while the SDK's buffer is nearly full and feed them in as it empties. That reads the processor's internal buffer, which isn't public API, so a supported signal would be better. With that in place, 8 load runs at 20 to 200 concurrent visitors lost 0 of 121,678 events, measured against the rows Flagsmith stored.
Versions
@flagsmith/nodejs 9.4.0; Flagsmith 2.291.0 (self-hosted, Docker); Node 24.
Found while building Turnout on self-hosted Flagsmith 2.291.0.
- Ngôn ngữ chính
- TypeScript
- Star
- 30
- Fork
- 30
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 11
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Flagsmith/flagsmith-nodejs-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 85/100
Flagsmith/flagsmith-nodejs-client#304 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Flagsmith/flagsmith-nodejs-client#286 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Flagsmith/flagsmith-nodejs-client#273 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[sdk/local-evaluation] Duplicate identity override entries silently drop feature overridesCó thể đã có người làm @xolott-ark đã nhận 203 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Flagsmith/flagsmith-nodejs-client#267 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của Flagsmith/flagsmith-nodejs-client
Issue tương tự
-
ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mermaid-js/mermaid-v13#1370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
compiler: the island_chunks_not_emitted report gives a count but not which islands were skippedĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Broken Website
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
darkreader/darkreader#16259 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
Maintainer thường phản hồi trong vòng 1 ngày