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

Abierto Apto para principiantes
#349,738 0 comentarios 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
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
electron, typescript

Línea de trabajo

Empieza en src/vs/platform/webContentExtractor/node/sharedWebContentExtractorService.ts, donde readImageWithMetadata llama a fetch sin signal ni plazo. Lee los stubs existentes en src/vs/platform/webContentExtractor/test/node/sharedWebContentExtractorService.test.ts y luego añade una prueba que compruebe que se pasa un signal y que cancelar el token aborta la solicitud. Se considera terminado cuando fetch está limitado por un timeout y vinculado al CancellationToken, y las pruebas pasan.

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

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
196k
Forks
43.9k
Merge medio
12 h 49 min
PR fusionados (30 d)
682

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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

Todos los issues de microsoft/vscode

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.