Upcoming papers sync can run twice at once and duplicate or empty the list

Aberta
#556 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 4 dias

@Dx-Alz-xD já está trabalhando nisso.

Desde 11/11/2026.

  • #563 de @Dx-Alz-xD — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
mongodb, typescript
Domínio
backend, databases

Direção de pesquisa

Read src/lib/services/upcoming-sync.ts, especially the date check and the deleteMany/insertMany sequence. The issue suggests claiming the day atomically and replacing subjects transactionally or with a bulk write; first check the open pull request #563 to understand work already underway. Done means concurrent requests cannot duplicate subjects or serve an empty list during the sync.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Describe the bug
checkAndSyncUpcomingSlots runs on the first /api/upcoming-papers request after the daily cutoff, it reads lastSyncedDate rebuilds the list and then does deleteMany({}) followed by insertMany(...), redudant

https://github.com/CodeChefVIT/papers-codechef/blob/6e3aa1152a34c7eb46d36f58294dffd9ff3b3c7b/src/lib/services/upcoming-sync.ts#L31
https://github.com/CodeChefVIT/papers-codechef/blob/6e3aa1152a34c7eb46d36f58294dffd9ff3b3c7b/src/lib/services/upcoming-sync.ts#L89-L103

Nothing stops two requests that arrive together from both seeing the old date and both running the sync, then:

  • both delete and both insert, so every upcoming subject can appear twice or
  • a request served between one syncs delete and its insert sees an empty list and gets a 404

To Reproduce
hard to hit by hand, Send several requests to /api/upcoming-papers at the same moment just after the cutoff on a day that hasnt synced yet, then check the upcomingsubjects collection for duplicates

Expected behavior
Only one request should run the sync. eg: claim the day atomically first with findOneAndUpdate({ lastSyncedDate: { $ne: today } }, { $set: { lastSyncedDate: today } }) and only sync if that update matched then replace the subjects in a transaction or with a bulk write

Linguagem predominante
TypeScript
Estrelas
23
Forks
67
Merge médio
2d 17h
PRs com merge (30d)
7

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de CodeChefVIT/papers-codechef

Todas as issues de CodeChefVIT/papers-codechef

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.