Give optional GitHub lookups a short timeout so a bad network does not stall linking

Aperta Adatta ai principianti
#747 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github, javascript, node.js

Direzione di ricerca

Leggi src/github-http.cjs per vedere come vengono usati REQUEST_TIMEOUT_MS e opts.setTimeout, poi segui isPullRequest in src/github-prs.js. Inizia da tests/unit/github-prs.test.cjs, che già inietta i timeout. Il lavoro è terminato quando il controllo della pull request si interrompe dopo circa 3 secondi, mentre le altre richieste a GitHub mantengono il timeout attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

What problem does this address?

Some GitHub lookups only add a nice-to-have, but they still wait the full 15-second request timeout when the network is connected and GitHub can't be reached. Think of a Contributor Day Wi-Fi with a sign-in page, or a proxy that drops requests.

The first one is the pull-request check on the Issue field (#736). Linking an issue on a Gutenberg site asks GitHub whether the number is a pull request first. If GitHub doesn't answer, the link still goes ahead, but only after up to 15 seconds of waiting.

What is your proposed solution?

Give lookups like this a short timeout, around 3 seconds, so the app gives up quickly and carries on as if the answer were "no".

Implementation notes

  • REQUEST_TIMEOUT_MS in src/github-http.cjs is a single constant for every request. httpRequest takes opts.setTimeout (for tests) but has no per-call timeout. Adding opts.timeoutMs, with the constant as the default, would leave every existing caller unchanged.
  • isPullRequest in src/github-prs.js (from #736) would pass the short timeout. It already treats any failure as "not a pull request", so a timeout needs no new handling.
  • Pre-checking net.isOnline() (main) or navigator.onLine (renderer) doesn't solve this. Both report whether the machine has a network connection, not whether GitHub is reachable, so they read as online in exactly the slow case. With no network at all, Chromium already fails the request almost at once.
  • Leave the timeout as it is for requests whose answer the user is waiting on, like opening a pull request, signing in, and the linked pull request list. A slow network there should fail with "Could not reach GitHub", not be cut short.
  • The unit tests in tests/unit/github-prs.test.cjs already drive timeouts with an injected setTimeout, so the short timeout can be tested without the network.
Lingua principale
JavaScript
Stelle
66
Fork
20
Merge medio
1g 18h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WordPress/contributor-toolkit

Tutte le issue di WordPress/contributor-toolkit

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.