chunk() never resets its size counter: past 500 KB every queued event is uploaded as its own request
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- react-native, typescript
Línea de trabajo
El error está en la función chunk en packages/core/src/util.ts. Comience leyendo la función y el ayudante sizeOf. El issue incluye un caso de reproducción y una solución sugerida. Pruebe la solución ejecutando las pruebas existentes para la lógica de fragmentación (chunking), o cree una pequeña prueba para verificar que el comportamiento corregido devuelva los 20 fragmentos esperados en lugar de miles. Busque cualquier prueba relacionada en el repositorio.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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;
};
- Lenguaje dominante
- TypeScript
- Estrellas
- 383
- Forks
- 206
- Merge medio
- 14 h 45 min
- PR fusionados (30 d)
- 11
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de segmentio/analytics-react-native
-
bug investigate
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
segmentio/analytics-react-native#1145 ·
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
segmentio/analytics-react-native#1328 ·
-
bug investigate
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
segmentio/analytics-react-native#1309 ·
-
Appsflyer Request: Delayed start Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
segmentio/analytics-react-native#1124 · 3 comentarios ·
-
Dont merge user traits Abiertoenhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
segmentio/analytics-react-native#1114 ·
Todos los issues de segmentio/analytics-react-native
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
security
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
IBM/node-sdk-core#373 ·
-
e2e-failure ready-to-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
chore
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100