chunk() never resets its size counter: past 500 KB every queued event is uploaded as its own request
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react-native, typescript
- Lĩnh vực
- backend-api-design, performance
Hướng nghiên cứu
Lỗi nằm trong hàm chunk trong packages/core/src/util.ts. Hãy bắt đầu bằng cách đọc hàm và trình trợ giúp sizeOf. Issue này bao gồm một trường hợp tái tạo và một bản sửa lỗi được đề xuất. Kiểm tra bản sửa lỗi bằng cách chạy các bài kiểm tra hiện có cho logic chunking, hoặc tạo một bài kiểm tra nhỏ để xác minh rằng hành vi đã sửa trả về 20 chunk như mong đợi thay vì hàng nghìn. Kiểm tra xem có bài kiểm tra liên quan nào trong kho lưu trữ không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
chunk() in packages/core/src/util.ts never resets rollingKBSize. Once the queue's running size reaches maxKB (MAX_PAYLOAD_SIZE_IN_KB = 500), every later event goes into its own chunk. SegmentDestination.sendEvents then uploads all chunks at once with Promise.all, so a single flush sends one HTTP request per queued event.
if (maxKB !== undefined) {
rollingKBSize += sizeOf(item);
if (rollingKBSize >= maxKB) {
chunks[++currentChunk] = [item]; // rollingKBSize is never reset
return chunks;
}
}
Reproduction
chunk(events, 1000, 500) with 10,000 events of about 1 KB each returns 9,481 chunks: one of 520 events, then 9,480 of one event each. The expected result is 20 chunks of about 520.
Impact
It shows up when the queue grows past 500 KB, which happens when uploads keep failing (for example, a device whose DNS blocks *.segmentapis.com). The queue persists across launches. If cdn-settings.segment.com is unreachable too, there's no httpConfig, so no backoff and no maxTotalBackoffDuration pruning, and maxQueueSize isn't enforced anywhere. In production we saw one iOS session make about 9,700 upload attempts in 91 seconds, at a steady ~60 per second (URLSession's 6 connections per host).
Version: 2.24.1. Same code on master.
Suggested fix
Keep a size counter per chunk and reset it when a new chunk starts, and push chunks instead of assigning by index. That also fixes the sparse-array case in #1309.
export const chunk = <T>(array: T[], count: number, maxKB?: number): T[][] => {
if (!array.length || !count) return [];
const result: T[][] = [];
let current: T[] = [];
let currentKB = 0;
for (const item of array) {
const itemKB = maxKB !== undefined ? sizeOf(item) : 0;
const isFull = current.length >= count || (maxKB !== undefined && currentKB + itemKB >= maxKB);
if (current.length > 0 && isFull) {
result.push(current);
current = [];
currentKB = 0;
}
current.push(item);
currentKB += itemKB;
}
if (current.length > 0) result.push(current);
return result;
};
- Ngôn ngữ chính
- TypeScript
- Star
- 384
- Fork
- 205
- Merge trung bình
- 12 giờ 17 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 segmentio/analytics-react-native
-
bug investigate
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
segmentio/analytics-react-native#1145 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
segmentio/analytics-react-native#1328 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug investigate
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
segmentio/analytics-react-native#1309 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Appsflyer Request: Delayed startĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
segmentio/analytics-react-native#1124 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dont merge user traitsĐang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
segmentio/analytics-react-native#1114 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của segmentio/analytics-react-native
Issue tương tự
-
priority: P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
prime-radiant-inc/evener#3291 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
accessibility bug revealjs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
quarto-dev/quarto-cli#14961 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
supabase/agent-skills#614 ·
-
Content
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
RunestoneInteractive/rs#1559 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày