Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

The last question's answers can be lost when a quiz ends

Abierto
#177 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, postgresql, typescript
Área
backend, database

Línea de trabajo

Start with apps/ws-server/src/utils/answerQueue.ts, focusing on flushSession, drainSession, and the insert-then-score-update sequence. Trace the quiz:end and end-of-questions callers, then locate the existing answer-queue tests and add coverage for an in-flight flush. Done means all buffered answers are written before the leaderboard is read, and answer persistence plus score updates are atomic or fully retryable.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Backend first issue bug help wanted

Answers are buffered in apps/ws-server/src/utils/answerQueue.ts and written in batches. Two paths in that file can lose a batch.

1. drainSession does not actually wait for an in-flight flush
export async function flushSession(sessionId: string): Promise<void> {
    if (flushing.has(sessionId)) return;     // resolves immediately
    ...
}

export async function drainSession(sessionId: string): Promise<void> {
    ...
    try {
        await flushSession(sessionId);       // a no-op if a flush is already running
    } catch { }
    ...
    buffers.delete(sessionId);               // deletes answers regardless
}

If a flush is already running, await flushSession() returns straight away without waiting for it, and drainSession goes on to delete the buffer. Two losses follow:

  • Answers that arrived during the in-flight write are still in buffers and are deleted unwritten.
  • If that in-flight flush then fails, its catch requeues into buffers.get(sessionId) — a map that was just deleted — so the requeue silently does nothing.

This fires on the hot path: drainSession runs at quiz:end and at end-of-questions, immediately after the final question closes, which is exactly when a flush is most likely to be in flight.

Impact: the final question's answers are missing from the leaderboard everyone finishes on, and there is no error anywhere.

2. A failed score update is never retried correctly

The flush inserts answers and then increments scores in two sequential awaits. If the insert succeeds and the score transaction fails, the whole batch is requeued — but on retry the rows already exist, skipDuplicates drops them all, and the returned set is empty. The score increments are skipped and never happen.

Result: ParticipantAnswer rows exist with the right points, while Participant.score was never incremented. The retry looks like a success. The leaderboard sorts on score, so the rankings stay wrong for the rest of the quiz.

What a fix looks like
  • Have flushSession return the in-flight promise rather than undefined, so callers can genuinely await it, and loop in drainSession until the buffer is empty before deleting.
  • Make the insert and the score increments atomic, or derive score from SUM(points) instead of incrementing — the data to reconcile is already in ParticipantAnswer.points.
Definition of done
  • Ending a quiz writes every buffered answer before the final leaderboard is read
  • A failed flush either fully applies or fully retries; no state where answers exist but scores do not
  • A test covering "flush in flight when the quiz ends"
Lenguaje dominante
TypeScript
Estrellas
21
Forks
7
Merge medio
4 h 31 min
PR fusionados (30 d)
22

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TheCodeHeist-Coder/Rexial

Todos los issues de TheCodeHeist-Coder/Rexial

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.