[GH-ISSUE #8974] server returns "Connection refused" when payload message contains () { #67881

Closed
opened 2026-05-04 11:57:31 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @glaudiston on GitHub (Feb 9, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8974

What is the issue?

ollama version is 0.5.7

aider chat was not working properly, then I did tcp dump and found that ollama was not allowing any requests where a message have a space between function and bracked, like () { ... it is OK to have (){ (without space).

LANG= curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc() {"}], "options": {"temperature": 0}, "stream": true}' -v
* Host localhost:11434 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:11434...
* connect to ::1 port 11434 from ::1 port 46660 failed: Connection refused
*   Trying 127.0.0.1:11434...
* Connected to localhost (127.0.0.1) port 11434
* using HTTP/1.x
> POST /api/chat HTTP/1.1
> Host: localhost:11434
> User-Agent: curl/8.11.1
> Accept: */*
> Content-Length: 143
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 143 bytes
* Recv failure: Connection reset by peer
* closing connection #0
curl: (56) Recv failure: Connection reset by peer

Without the space everything works as expected:

LANG= curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc(){"}], "options": {"temperature": 0}, "stream": true}' -v
* Host localhost:11434 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:11434...
* connect to ::1 port 11434 from ::1 port 58644 failed: Connection refused
*   Trying 127.0.0.1:11434...
* Connected to localhost (127.0.0.1) port 11434
* using HTTP/1.x
> POST /api/chat HTTP/1.1
> Host: localhost:11434
> User-Agent: curl/8.11.1
> Accept: */*
> Content-Length: 142
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 142 bytes
< HTTP/1.1 200 OK
< Content-Type: application/x-ndjson
< Date: Sun, 09 Feb 2025 18:20:59 GMT
< Transfer-Encoding: chunked
< 
{"model":"deepseek-r1:70b","created_at":"2025-02-09T18:20:59.006403671Z","message":{"role":"assistant","content":"\u003cthink\u003e"},"done":false}
...

same behavior tested with model llama3.3:latest.

Relevant log output

Aider output (only relevant to help others to find this issue)
Traceback (most recent call last):
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions
    yield
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 236, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 256, in handle_request
    raise exc from None
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 236, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
    return self._connection.handle_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 136, in handle_request
    raise exc
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 106, in handle_request
    ) = self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 177, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 217, in _receive_event
    data = self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 126, in read
    with map_exceptions(exc_map):
  File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1303, in send_message
    yield from self.send(messages, functions=self.functions)
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1634, in send
    yield from self.show_send_output_stream(completion)
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1709, in show_send_output_stream
    for chunk in completion:
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/litellm/llms/ollama_chat.py", line 377, in ollama_completion_stream
    with httpx.stream(**_request) as response:
  File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_api.py", line 172, in stream
    with client.stream(
  File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 880, in stream
    response = self.send(
               ^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 926, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 954, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 991, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 1027, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 235, in handle_request
    with map_httpcore_exceptions():
  File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: [Errno 104] Connection reset by peer

[Errno 104] Connection reset by peer

OS

Linux

GPU

Nvidia

CPU

Intel

Ollama version

0.5.7

Originally created by @glaudiston on GitHub (Feb 9, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8974 ### What is the issue? ollama version is 0.5.7 aider chat was not working properly, then I did tcp dump and found that ollama was not allowing any requests where a message have a space between function and bracked, like `() {` ... it is OK to have `(){` (without space). ``` LANG= curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc() {"}], "options": {"temperature": 0}, "stream": true}' -v * Host localhost:11434 was resolved. * IPv6: ::1 * IPv4: 127.0.0.1 * Trying [::1]:11434... * connect to ::1 port 11434 from ::1 port 46660 failed: Connection refused * Trying 127.0.0.1:11434... * Connected to localhost (127.0.0.1) port 11434 * using HTTP/1.x > POST /api/chat HTTP/1.1 > Host: localhost:11434 > User-Agent: curl/8.11.1 > Accept: */* > Content-Length: 143 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 143 bytes * Recv failure: Connection reset by peer * closing connection #0 curl: (56) Recv failure: Connection reset by peer ``` Without the space everything works as expected: ``` LANG= curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc(){"}], "options": {"temperature": 0}, "stream": true}' -v * Host localhost:11434 was resolved. * IPv6: ::1 * IPv4: 127.0.0.1 * Trying [::1]:11434... * connect to ::1 port 11434 from ::1 port 58644 failed: Connection refused * Trying 127.0.0.1:11434... * Connected to localhost (127.0.0.1) port 11434 * using HTTP/1.x > POST /api/chat HTTP/1.1 > Host: localhost:11434 > User-Agent: curl/8.11.1 > Accept: */* > Content-Length: 142 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 142 bytes < HTTP/1.1 200 OK < Content-Type: application/x-ndjson < Date: Sun, 09 Feb 2025 18:20:59 GMT < Transfer-Encoding: chunked < {"model":"deepseek-r1:70b","created_at":"2025-02-09T18:20:59.006403671Z","message":{"role":"assistant","content":"\u003cthink\u003e"},"done":false} ... ``` same behavior tested with model `llama3.3:latest`. ### Relevant log output ```shell Aider output (only relevant to help others to find this issue) Traceback (most recent call last): File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions yield File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 236, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 256, in handle_request raise exc from None File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 236, in handle_request response = connection.handle_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 103, in handle_request return self._connection.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 136, in handle_request raise exc File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 106, in handle_request ) = self._receive_response_headers(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 177, in _receive_response_headers event = self._receive_event(timeout=timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 217, in _receive_event data = self._network_stream.read( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 126, in read with map_exceptions(exc_map): File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ReadError: [Errno 104] Connection reset by peer The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1303, in send_message yield from self.send(messages, functions=self.functions) File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1634, in send yield from self.show_send_output_stream(completion) File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/aider/coders/base_coder.py", line 1709, in show_send_output_stream for chunk in completion: File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/litellm/llms/ollama_chat.py", line 377, in ollama_completion_stream with httpx.stream(**_request) as response: File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 137, in __enter__ return next(self.gen) ^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_api.py", line 172, in stream with client.stream( File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 137, in __enter__ return next(self.gen) ^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 880, in stream response = self.send( ^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 926, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 954, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 991, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_client.py", line 1027, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 235, in handle_request with map_httpcore_exceptions(): File "/home/glaudiston/miniforge3/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/home/glaudiston/miniforge3/lib/python3.11/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ReadError: [Errno 104] Connection reset by peer [Errno 104] Connection reset by peer ``` ### OS Linux ### GPU Nvidia ### CPU Intel ### Ollama version 0.5.7
GiteaMirror added the bug label 2026-05-04 11:57:31 -05:00
Author
Owner

@rick-github commented on GitHub (Feb 9, 2025):

$ curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc() {"}], "options": {"temperature": 0}, "stream": true}'
{"model":"deepseek-r1:70b","created_at":"2025-02-09T19:22:44.787916042Z","message":{"role":"assistant","content":"\u003cthink\u003e"},"done":false}
{"model":"deepseek-r1:70b","created_at":"2025-02-09T19:22:45.469727777Z","message":{"role":"assistant","content":"\n"},"done":false}

Works here. Server logs may aid in debugging.

<!-- gh-comment-id:2646550792 --> @rick-github commented on GitHub (Feb 9, 2025): ```console $ curl localhost:11434/api/chat --data '{"model": "deepseek-r1:70b","messages": [{"role":"user","content":"function myCustomFunc() {"}], "options": {"temperature": 0}, "stream": true}' {"model":"deepseek-r1:70b","created_at":"2025-02-09T19:22:44.787916042Z","message":{"role":"assistant","content":"\u003cthink\u003e"},"done":false} {"model":"deepseek-r1:70b","created_at":"2025-02-09T19:22:45.469727777Z","message":{"role":"assistant","content":"\n"},"done":false} ``` Works here. [Server logs](https://github.com/ollama/ollama/blob/main/docs/troubleshooting.md#how-to-troubleshoot-issues) may aid in debugging.
Author
Owner

@glaudiston commented on GitHub (Feb 9, 2025):

OK, I can confirm that it works directly on the host. My current setup is forwarding localhost packages via iptables to a remote host. Probably some package filtering tool on the cloud.

<!-- gh-comment-id:2646598945 --> @glaudiston commented on GitHub (Feb 9, 2025): OK, I can confirm that it works directly on the host. My current setup is forwarding localhost packages via iptables to a remote host. Probably some package filtering tool on the cloud.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#67881