# Distributed worker detect ip address via socket connection?

**URL:** https://discourse.julialang.org/t/distributed-worker-detect-ip-address-via-socket-connection/88068
**Category:** General Usage
**Created:** [October 1, 2022, 2:38am UTC](https://discourse.julialang.org/t/distributed-worker-detect-ip-address-via-socket-connection/88068 "2022-10-01T02:38:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 1, 2022, 2:38am UTC](https://discourse.julialang.org/t/distributed-worker-detect-ip-address-via-socket-connection/88068/1 "2022-10-01T02:38:35Z")

</div>

Right now there’s this kinda dumb logic going on:

> <https://github.com/JuliaParallel/ClusterManagers.jl/blob/ff73e36e108cfd6810d6689c51696930a7503f63/src/condor.jl#L69-L70>

1. submit jobs for worker nodes to launch `julia --worker=<cookie> | nc <hostip> <hostport>`
2. the `julia --worker=<cookie>` would print out the `julia_worker:workerport#workerip`
3. the host parses the `netcat` content and use the worker IP and worker port and take over from there

BUT, the `workerip` reported by worker can be total garbage because it simply takes the first `IPv4` interface:

> <https://github.com/JuliaLang/julia/blob/0d00660a38f4d4049e12a97399e4ef613bf0d7dc/stdlib/Sockets/src/addrinfo.jl#L272-L276>

which means it can well be a local IP like `192.168.1.xx` especially if the worker runs in a container or has virtual interface for some other reason

Shouldn’t the logic be that host uses the source IP address that sent the `netcat` in the first place as the worker IP?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 1, 2022, 3:27am UTC](https://discourse.julialang.org/t/distributed-worker-detect-ip-address-via-socket-connection/88068/2 "2022-10-01T03:27:25Z")

</div>

> <https://github.com/JuliaLang/julia/issues/46995>
>
> https://github.com/JuliaLang/julia/blob/0d00660a38f4d4049e12a97399e4ef613bf0d7dc…/stdlib/Distributed/src/managers.jl#L568
> 
> for some reason we don't use the fact that we can call \`Sockets.getpeername()\` here, instead we read the stdout of the worker process.
> 
> This is problemmatic mainly because:
> 1. the worker nodes always report the first IPv4 interface's address no matter if that's actually the interface it used to contact main node:
> https://github.com/JuliaLang/julia/blob/0d00660a38f4d4049e12a97399e4ef613bf0d7dc/stdlib/Sockets/src/addrinfo.jl#L272-L276
> 
> 2. the worker node may be running inside container (or whatever reason has virtual interface before everything else)
> 
> my questions: can we add a specialization for \`read\_worker\_host\_port\` when \`config.io :: Sockets.TCPSocket\`?
