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

Open Beginner friendly
#349,738 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
electron, typescript

Research direction

Start in src/vs/platform/webContentExtractor/node/sharedWebContentExtractorService.ts, where readImageWithMetadata calls fetch without a signal or deadline. Read the existing stubs in src/vs/platform/webContentExtractor/test/node/sharedWebContentExtractorService.test.ts, then add a test that checks a signal is passed and that cancelling the token aborts the request. Done when the fetch is bounded by a timeout and tied to the CancellationToken, and the tests pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
196k
Forks
43.9k
Avg merge
12h 49m
Merged PRs (30d)
682

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode

All issues in microsoft/vscode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.