Distributed worker detect ip address via socket connection?

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

  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:

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?