Skip to content

server: Fix router proxying to child processes when --host is specified#18054

Closed
wbtek wants to merge 1 commit intoggml-org:masterfrom
wbtek:fix/router-host-binding
Closed

server: Fix router proxying to child processes when --host is specified#18054
wbtek wants to merge 1 commit intoggml-org:masterfrom
wbtek:fix/router-host-binding

Conversation

@wbtek
Copy link
Copy Markdown
Contributor

@wbtek wbtek commented Dec 15, 2025

llama-server --host now works for:

  • specific external facing addresses both locally and externally (192.168.3.14)
  • localhost (127.0.0.1)
  • all interfaces (0.0.0.0)

It worked with 127.0.0.1 and 0.0.0.0 before, but when a specific external facing address was specified it:

  • served the WebUI correctly on the specified ip address
  • switched to 127.0.0.1 for child when model was loaded and failed

@aldehir
Copy link
Copy Markdown
Contributor

aldehir commented Dec 15, 2025

This breaks --host 0.0.0.0 on Windows.

inst.meta.port = get_free_port();
inst.meta.status = SERVER_MODEL_STATUS_LOADING;
inst.meta.last_used = ggml_time_ms();
inst.meta.hostname = base_params.hostname; // Use router's cmdline value
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.0.0.0 does not route to 127.0.0.1 on Windows like it does on Linux.

A quick fix may be to only change to 127.0.0.1 on --host 0.0.0.0, otherwise use the provided IP.

#17962 (comment)

auto proxy = std::make_unique<server_http_proxy>(
method,
CHILD_ADDR,
base_params.hostname,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented Dec 15, 2025

I still don't get the use case of this PR

the webui is served by router, it should use IP of router

@aldehir
Copy link
Copy Markdown
Contributor

aldehir commented Dec 15, 2025

@ngxson when binding to a specific IP, the socket will not accept traffic from 127.0.0.1. So when the client tries to connect to the router, it fails. This isn't a problem if using 0.0.0.0 because it accepts traffic from all interfaces.

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 16, 2025

I still don't get the use case of this PR

the webui is served by router, it should use IP of router

@ngxson Use case: --host 192.168.33.44 serves 1 (trusted) interface of n. --host 0.0.0.0 serves all n (trusted or not).

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 16, 2025

This breaks --host 0.0.0.0 on Windows.

@aldehir My understanding (which is not guaranteed correct) is that Windows and Linux from the app side both listen on all interfaces if the app binds to 0.0.0.0. However, if the browser tries to connect on 0.0.0.0 on Windows that is invalid, but on Linux that would be treated as 127.0.0.1.

When I tested --host 0.0.0.0, I tried connecting to both 127.0.0.1 and 192.168.xx.yy from the browser and it worked. Is that what you are trying to do?

I just also did try connecting from the browser to 0.0.0.0 and that worked too. It turned into 127.0.0.1. I'm not sure that is valid to even try from Windows tho. Is it?

@aldehir
Copy link
Copy Markdown
Contributor

aldehir commented Dec 16, 2025

@wbtek on Windows, correct? Did you try loading a model? The issue isn't the browser hitting the router, that works as you described. The issue is the child attempts to reach the router at 0.0.0.0.

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 16, 2025

@wbtek on Windows, correct? Did you try loading a model? The issue isn't the browser hitting the router, that works as you describe. The issue is the child attempts to reach the router at 0.0.0.0.

@aldehir I don't have a Windows machine, only Linux.

But yes, i loaded a model for all three cases and asked a question. All three worked. I was on the same (local) machine in all three cases.

@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented Dec 16, 2025

I think we are going to the wrong direction here.

If I understand correctly, the bug was that router instance may not listen on 127.0.0.1, so the model instance cannot report its ready state to router. However, the request from router to model instance still work correctly because model instance is guaranteed to listen on 127.0.0.1

If this is the case, the fix is to allow using stdout to report model status back to server.

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 16, 2025

I think we are going to the wrong direction here.

If I understand correctly, the bug was that router instance may not listen on 127.0.0.1, so the model instance cannot report its ready state to router. However, the request from router to model instance still work correctly because model instance is guaranteed to listen on 127.0.0.1

If this is the case, the fix is to allow using stdout to report model status back to server.

@ngxson I'm sorry for my poor writing. I'll state the original problem more simply, just in case. Accept this as just input, please do whatever you want with it. Thanks for your great work! :)

Background:

--host 0.0.0.0 binds to all interfaces, which can be a security risk. What if only one network is trusted?

--host 11.22.33.44 binds to only one interface. Only connections on that interface are accepted for better security.

The problem:

Only --host 0.0.0.0 and --host 127.0.0.1 work. The child is hardwired to only talk on 127.0.0.1. The WebUI is correctly served where --host specifies, but if that doesn't happen to be 127.0.0.1 communication stops after the model loads.

This PR:

Uses the host specified by --host for the child addr too.

@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented Dec 16, 2025

Please give a try with #18110

Uses the host specified by --host for the child addr too.

IMO it doesn't fix the root cause, the child should always listen via 127.0.0.1

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 17, 2025

Please give a try with #18110

Uses the host specified by --host for the child addr too.

IMO it doesn't fix the root cause, the child should always listen via 127.0.0.1

@ngxson I tried your fix with --host 0.0.0.0, 127.0.0.1, 192.168.xx.yy (on Linux only). It worked/failed correctly for every internal/external case I tried. Awesome, thx! :)

@wbtek
Copy link
Copy Markdown
Contributor Author

wbtek commented Dec 17, 2025

Closing this PR. Issue resolved by @ngxson PR #18110. I verified his solution works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants