Skip to content
Source
Sign inSign up
TanStack/ai

Ollama chat adapter does not forward the request abort signal to the ollama SDK #1644

Closedchooquantavia(GitHub profile, opens in a new tab) opened this issue 0 comments

TanStack AI version

0.65.0 (also seen on 0.64.0)

Framework/Library version

@tanstack/ai-ollama: 0.11.13 (also 0.11.12) | ollama: 0.6.4 | Node.js 24.16.0

Describe the bug and the steps to reproduce it

Calling abortController.abort() on a chat() run that uses the Ollama adapter does not cancel the adapter's in-flight HTTP request to Ollama. The run's signal becomes aborted, but the request stays open until Node's HTTP client gives up on its own (its default headers timeout is 300 s). Ollama keeps generating a response nobody will read, and the process cannot exit until then.

The chat engine passes its effective request to adapter.chatStream(), including the caller's abort signal.

The Ollama adapter calls the ollama SDK without it, on both paths:

  • chatStream: this.client.chat({ ...mappedOptions, stream: true })
  • structuredOutput: this.client.chat({ ...mappedOptions, stream: false, format: outputSchema })

The string abort does not occur anywhere in the published @tanstack/ai-ollama 0.11.13 build.

Steps to reproduce (no Ollama install or model needed):

  1. Download the two files from the gist below, then run npm install && node repro.mjs.
  2. The script starts a local HTTP server that stands in for Ollama and never answers POST /api/chat. It records when the request's socket closes.
  3. It runs three cases, each aborting after 500 ms and waiting up to 10 s for the socket to close:
    • control: a plain fetch to the same server with the same signal
    • chatStream: chat() with createOllamaChat("any-model", host)
    • structuredOutput: the same, with an outputSchema

Output:

[control] server: POST /api/chat received, never answering
[control] client: abortController.abort() called
[control] RESULT: request closed 9 ms after abort
[chatStream] server: POST /api/chat received, never answering
[chatStream] client: abortController.abort() called
[chatStream] RESULT: request still open 10000 ms after abort (expected: closed promptly)
[structuredOutput] server: POST /api/chat received, never answering
[structuredOutput] client: abortController.abort() called
[structuredOutput] RESULT: request still open 10000 ms after abort (expected: closed promptly)

We hit this with a 5-minute timeout around a chat() call against a slow Ollama host. The timeout fired and aborted the run, but the request stayed open and later failed with UND_ERR_HEADERS_TIMEOUT.

Expected behavior

The abort reaches the HTTP request, as it already does for the OpenAI-compatible adapters and, since #1374, for Gemini.

A note on a possible fix, not verified: ollama 0.6.4 takes no per-call signal. It can abort a streamed response through AbortableAsyncIterator.abort() or client.abort() (which aborts every stream on the client), but both only exist once the response headers have arrived. A per-call fetch that honours options.request.signal may be needed to also cover the wait for headers and the non-streaming structuredOutput call.

https://gist.github.com/chooquantavia/4c666847dee24c05297900d0acd2fcaa

Do you intend to try to help solve this bug with your own PR?

No, because I do not have time to dig into it

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

  2. AlemTuzlak closed this

Sign in to join this conversation.