Chat image download from URL has no timeout and ignores its cancellation token

Aperta Adatta ai principianti
#349,738 0 commenti 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
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
electron, typescript

Direzione di ricerca

Inizia da src/vs/platform/webContentExtractor/node/sharedWebContentExtractorService.ts, dove readImageWithMetadata chiama fetch senza signal né scadenza. Leggi gli stub esistenti in src/vs/platform/webContentExtractor/test/node/sharedWebContentExtractorService.test.ts, poi aggiungi un test che verifichi che un signal venga passato e che annullare il token interrompa la richiesta. Il lavoro è completo quando fetch è limitato da un timeout e legato al CancellationToken, e i test passano.

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

Descrizione

Does this issue occur when all extensions are disabled?: Yes (core code path, no extension involved)

  • VS Code Version: main at 742a9ae378720f2526ed7128fbc47ec2a285f1b1 (found by reading the source, not reproduced in a build)
  • OS Version: any

SharedWebContentExtractorService.readImageWithMetadata downloads an image from an arbitrary URL with a plain fetch and no deadline:

https://github.com/microsoft/vscode/blob/742a9ae378720f2526ed7128fbc47ec2a285f1b1/src/vs/platform/webContentExtractor/node/sharedWebContentExtractorService.ts#L26-L35

The CancellationToken is checked once before the request and is never connected to the fetch, so even a cancelled token cannot abort it. In practice every workbench caller passes CancellationToken.None anyway:

  • chat drag and drop: chatDragAndDrop.ts#L446
  • attachments: chatAttachmentModel.ts#L203
  • input part: chatInputPart.ts#L2900
  • copy image: chatImageActions.ts#L50
  • image generation batch: chatImageGenerationBatchPart.ts#L282
  • download: workbench/browser/download.ts#L36

Steps to Reproduce:

  1. Serve a URL that accepts the connection and never sends a response (for example nc -l 8080).
  2. Drag http://localhost:8080/a.png into the Chat input, or paste it as an image attachment.
  3. Nothing aborts the request, so the attachment stays pending until Node's fetch gives up after undici's default headers/body timeouts (300 s each), and there is no way to cancel it from the UI.

Expected: the request is bounded and cancellable. A small fix is to pass a signal that combines a timeout with the token, e.g.

const controller = new AbortController();
const listener = token.onCancellationRequested(() => controller.abort());
try {
	const response = await fetch(uri.toString(true), {
		headers: { ... },
		signal: AbortSignal.any([controller.signal, AbortSignal.timeout(30_000)]),
	});
	...
} finally {
	listener.dispose();
}

The existing tests in src/vs/platform/webContentExtractor/test/node/sharedWebContentExtractorService.test.ts stub fetch, so a case asserting that a signal is passed and that cancelling the token aborts it would fit there. I can send a PR with that if it helps.

Lingua principale
TypeScript
Stelle
196k
Fork
43.9k
Merge medio
12h 49m
PR unite (30g)
682

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 microsoft/vscode

Tutte le issue di microsoft/vscode

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.