Comments (11)
Thanks for raising the issue. The way in which a service registers, it blindly uses the server listener address provided rather than figuring out the appropriate IP of the machine or allow you to specify and advertising address. The quick fix is to set server.Address("10.0.0.1:8080") to the private ip of the host. I'll put together a more elegant solution that will either allow the separation of listen and advertise address much like consul does. Any thoughts or PRs welcome.
from go-micro.
Thank you @asim , the quick fix worked !
from go-micro.
I've committed a fix here 0dbe14a. When 0.0.0.0 is specified as the bind address it will extract the private ip and use that for registration. Please close the issue if to satisfaction.
from go-micro.
Not sure if this is the way to do it, but it's not working here
server.Init(
server.Name("io.jbrodriguez.mediagui.scanner."+host),
server.Address("0.0.0.0:0"),
)
root@wopr:~# /boot/scanner -logtostderr
I1104 17:03:34.004338 7537 scanner.go:55] Scanner started
I1104 17:03:34.004415 7537 server.go:96] Starting server io.jbrodriguez.mediagui.scanner.wopr id io.jbrodriguez.mediagui.scanner.wopr-e43c7501-833f-11e5-9483-d05099660776
I1104 17:03:34.004576 7537 rpc_server.go:222] Listening on 0.0.0.0:39241
I1104 17:03:34.004666 7537 http_broker.go:80] Broker Listening on 0.0.0.0:43409
I1104 17:03:34.004720 7537 rpc_server.go:152] Registering node: io.jbrodriguez.mediagui.scanner.wopr-e43c7501-833f-11e5-9483-d05099660776
[
{
"Node": "io.jbrodriguez.mediagui.scanner.wopr-e43c7501-833f-11e5-9483-d05099660776",
"Address": "0.0.0.0",
"ServiceID": "io.jbrodriguez.mediagui.scanner.wopr-e43c7501-833f-11e5-9483-d05099660776",
"ServiceName": "io.jbrodriguez.mediagui.scanner.wopr",
"ServiceTags": [
"e={\"Name\":\"Scanner.Scan\",\"Request\":{\"Name\":\"Request\",\"Type\":\"Request\",\"Values\":[{\"Name\":\"Folders\",\"Type\":\"\",\"Values\":null}]},\"Response\":{\"Name\":\"Response\",\"Type\":\"Response\",\"Values\":[{\"Name\":\"Filenames\",\"Type\":\"\",\"Values\":null}]},\"Metadata\":{\"stream\":\"false\"}}",
"e={\"Name\":\"Debug.Health\",\"Request\":{\"Name\":\"Request\",\"Type\":\"Request\",\"Values\":null},\"Response\":{\"Name\":\"Response\",\"Type\":\"Response\",\"Values\":[{\"Name\":\"Status\",\"Type\":\"string\",\"Values\":null}]},\"Metadata\":{\"stream\":\"false\"}}"
],
"ServiceAddress": "",
"ServicePort": 39241
}
]
from go-micro.
I think this line will never evaluate to true
0dbe14a#diff-83b1f985ddf5acc292d6df4ede4b6395R143
from go-micro.
Does your machine have private ips?
from go-micro.
Yes, 192.168.23.x
from go-micro.
The IPs are assigned on the machine and you can see them if you do ifconfig?
from go-micro.
Yes, I have docker running but that's a different issue
root@wopr:~# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.42.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 36:dd:68:31:e1:d2 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 558 bytes 72965 (71.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.23.72 netmask 255.255.255.0 broadcast 192.168.23.255
ether d0:50:99:66:07:76 txqueuelen 1000 (Ethernet)
RX packets 438818 bytes 481549074 (459.2 MiB)
RX errors 0 dropped 1817 overruns 0 frame 0
TX packets 210916 bytes 107895564 (102.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xefd00000-efd20000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 0 (Local Loopback)
RX packets 2925 bytes 35495980 (33.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2925 bytes 35495980 (33.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I'm running your code inside the service handler and it works
for _, b := range []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"} {
if _, block, err := net.ParseCIDR(b); err == nil {
privateBlocks = append(privateBlocks, block)
}
}
addrs, err := net.InterfaceAddrs()
if err != nil {
log.Info("Oops: " + err.Error() + "\n")
os.Exit(1)
}
ip := "0.0.0.0"
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
for _, priv := range privateBlocks {
tip := net.ParseIP(ipnet.IP.String())
if priv.Contains(tip) {
log.Info("inside")
ip = ipnet.IP.String()
}
}
// if strings.Contains(ipnet.IP.String(), "192.168.0.0/16") {
// ip = ipnet.IP.String()
}
}
}
log.Infof("Ip=%s", ip)
outputs
root@wopr:~# /boot/scanner -logtostderr
I1104 17:24:29.243671 3652 scanner.go:46] inside
I1104 17:24:29.243757 3652 scanner.go:46] inside
I1104 17:24:29.243780 3652 scanner.go:56] Ip=172.17.42.1
I1104 17:24:29.243826 3652 scanner.go:71] Scanner started
I1104 17:24:29.243847 3652 server.go:96] Starting server io.jbrodriguez.mediagui.scanner.wopr id io.jbrodriguez.mediagui.scanner.wopr-d06a9fb1-8342-11e5-b6a2-d05099660776
I1104 17:24:29.243953 3652 rpc_server.go:222] Listening on 0.0.0.0:38084
I1104 17:24:29.244032 3652 http_broker.go:80] Broker Listening on 0.0.0.0:47733
I1104 17:24:29.244103 3652 rpc_server.go:152] Registering node: io.jbrodriguez.mediagui.scanner.wopr-d06a9fb1-8342-11e5-b6a2-d05099660776
^CI1104 17:26:00.164628 3652 server.go:85] Received signal interrupt
I1104 17:26:00.164654 3652 rpc_server.go:196] Deregistering node: io.jbrodriguez.mediagui.scanner.wopr-d06a9fb1-8342-11e5-b6a2-d05099660776
I1104 17:26:00.166701 3652 server.go:101] Stopping server
root@wopr:~# /boot/scanner -logtostderr
I1104 17:26:14.362823 6063 scanner.go:46] inside
I1104 17:26:14.362917 6063 scanner.go:46] inside
I1104 17:26:14.362950 6063 scanner.go:56] Ip=172.17.42.1
I1104 17:26:14.363032 6063 scanner.go:71] Scanner started
I1104 17:26:14.363089 6063 server.go:96] Starting server io.jbrodriguez.mediagui.scanner.wopr id io.jbrodriguez.mediagui.scanner.wopr-0f129758-8343-11e5-b8a2-d05099660776
I1104 17:26:14.363253 6063 rpc_server.go:222] Listening on 0.0.0.0:46509
I1104 17:26:14.363343 6063 http_broker.go:80] Broker Listening on 0.0.0.0:48304
I1104 17:26:14.363398 6063 rpc_server.go:152] Registering node: io.jbrodriguez.mediagui.scanner.wopr-0f129758-8343-11e5-b8a2-d05099660776
^CI1104 17:26:22.837228 6063 server.go:85] Received signal interrupt
I1104 17:26:22.837351 6063 rpc_server.go:196] Deregistering node: io.jbrodriguez.mediagui.scanner.wopr-0f129758-8343-11e5-b8a2-d05099660776
I1104 17:26:22.840463 6063 server.go:101] Stopping server
from go-micro.
Did you do go get -u? Perhaps the library was not rebuilt the first time. The behaviour suggests it wasn't updated.
from go-micro.
That was it.
Thanks @asim !!
from go-micro.
Related Issues (20)
- [go-micro/auth.Inspect()] Is this function working? HOT 2
- how can i writter log to file? HOT 4
- [BUG]micro v4 can't register service HOT 10
- how can i pass http request headers through metadata?
- [BUG] go.micro.client.transport write: broken pipe
- [BUG] for v4.9.0 to RegisterSubscriber with Queue
- go-micro v4版本 客户端请求超时,,在go-micro怎么配置请求时间 HOT 2
- v4 v4.10.2 can't subscribe kafka topic anymore? HOT 1
- call Requset Timeout with detail <nil> HOT 2
- Using rabbitmq as broker in service , fail to publish mq message with " service not found" HOT 1
- Doesn't go-micro support lowercase grpc method name in proto ? HOT 1
- Client-side Retries mechanism causes server-side code to be called multiple times HOT 1
- [BUG] v2 has no dependency to github.com/micro/cli/v2 v2.1.2 HOT 1
- [BUG] v4.9.0 rpc_server.go register function read lock re-entry HOT 1
- [BUG]V4.10.2 rpc_client.go Call function easily happen RWMutex‘s read lock re-entry then deadlock HOT 1
- [BUG] WARNING: DATA RACE HOT 1
- Notice: Looking for a new owner HOT 17
- How to use protobuf generation when upgrading go-micro from v4 to v5? HOT 4
- why delete the cli HOT 1
- v5 event package HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-micro.