Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Error when binding net addr to 0.0.0.0 #7

Closed
labkode opened this issue Jun 21, 2021 · 13 comments
Closed

Error when binding net addr to 0.0.0.0 #7

labkode opened this issue Jun 21, 2021 · 13 comments
Labels
OCIS-Fastlane Planned outside of the sprint

Comments

@labkode
Copy link
Member

labkode commented Jun 21, 2021

When binding the server to 0.0.0.0 is gives the following error:

ocis-wopiserver server --http-addr 0.0.0.0:1111
{"level":"error","service":"wopiserver","error":"address ::1:1111: too many colons in address","transport":"http","time":"2021-06-21T11:10:23+02:00","message":"Failed to start server"}

When running with localhost it works:

ocis-wopiserver server --http-addr localhost:1111
@wkloucek
Copy link
Contributor

Note: @labkode reported that oCIS can be started without problems

@micbar micbar added the OCIS-Fastlane Planned outside of the sprint label Jun 21, 2021
@wkloucek
Copy link
Contributor

wkloucek commented Jun 21, 2021

Could you please try --http-addr '[0.0.0.0]:1111' / --http-addr '[::0]:1111' ?

Edit: more about the square bracket notation: https://pkg.go.dev/net#Dial

@labkode
Copy link
Member Author

labkode commented Jun 21, 2021

@wkloucek same error:

[13:51][root@cbox-ocisdev-03 (ocis_dev:box/ocis) ~]# ocis-wopiserver server --http-addr "[0.0.0.0]:9505"
{"level":"info","service":"wopiserver","time":"2021-06-21T13:51:54+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","time":"2021-06-21T13:51:54+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","transport":"http","addr":"[0.0.0.0]:9505","time":"2021-06-21T13:51:54+02:00","message":"starting server"}
{"level":"info","service":"wopiserver","transport":"debug","addr":"0.0.0.0:9109","time":"2021-06-21T13:51:54+02:00","message":"starting server"}
2021-06-21 13:51:54  file=v3@v3.5.1-0.20210217182006-0f0ace1a44a9/service.go:192 level=info Starting [service] com.owncloud.web.
{"level":"info","service":"wopiserver","transport":"http","time":"2021-06-21T13:51:54+02:00","message":"Shutting down server"}
2021-06-21 13:51:54  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:255 level=info Listening on [::]:9505
2021-06-21 13:51:54  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:169 level=info Registering node: com.owncloud.web.-fb7ddaf2-3664-4b8a-9e34-e1134656aa6a
{"level":"error","service":"wopiserver","error":"address ::1:9505: too many colons in address","transport":"http","time":"2021-06-21T13:51:54+02:00","message":"Failed to start server"}



[13:51][root@cbox-ocisdev-03 (ocis_dev:box/ocis) ~]# ocis-wopiserver server --http-addr "[::0]:9505"
{"level":"info","service":"wopiserver","time":"2021-06-21T13:52:07+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","time":"2021-06-21T13:52:07+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","transport":"http","addr":"[::0]:9505","time":"2021-06-21T13:52:07+02:00","message":"starting server"}
{"level":"info","service":"wopiserver","transport":"debug","addr":"0.0.0.0:9109","time":"2021-06-21T13:52:07+02:00","message":"starting server"}
2021-06-21 13:52:07  file=v3@v3.5.1-0.20210217182006-0f0ace1a44a9/service.go:192 level=info Starting [service] com.owncloud.web.
{"level":"info","service":"wopiserver","transport":"http","time":"2021-06-21T13:52:07+02:00","message":"Shutting down server"}
2021-06-21 13:52:07  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:255 level=info Listening on [::]:9505
2021-06-21 13:52:07  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:169 level=info Registering node: com.owncloud.web.-f8a2ce75-221e-4dff-b97d-6307d8b74999
{"level":"error","service":"wopiserver","error":"address ::1:9505: too many colons in address","transport":"http","time":"2021-06-21T13:52:07+02:00","message":"Failed to start server"}

@labkode
Copy link
Member Author

labkode commented Jun 21, 2021

If I use [::1]:9505 looks like it works:

[13:53][root@cbox-ocisdev-03 (ocis_dev:box/ocis) ~]# ocis-wopiserver server --http-addr "[::1]:9505"
{"level":"info","service":"wopiserver","time":"2021-06-21T13:53:29+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","time":"2021-06-21T13:53:29+02:00","message":"Continue without config"}
{"level":"info","service":"wopiserver","transport":"http","addr":"[::1]:9505","time":"2021-06-21T13:53:29+02:00","message":"starting server"}
{"level":"info","service":"wopiserver","transport":"debug","addr":"0.0.0.0:9109","time":"2021-06-21T13:53:29+02:00","message":"starting server"}
2021-06-21 13:53:29  file=v3@v3.5.1-0.20210217182006-0f0ace1a44a9/service.go:192 level=info Starting [service] com.owncloud.web.
2021-06-21 13:53:29  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:255 level=info Listening on [::1]:9505
{"level":"info","service":"wopiserver","transport":"http","time":"2021-06-21T13:53:29+02:00","message":"Shutting down server"}
2021-06-21 13:53:29  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:169 level=info Registering node: com.owncloud.web.-f730bbd9-e80e-475a-9d8d-885639a7ff4a
2021-06-21 13:53:29  file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:209 level=info Deregistering node: com.owncloud.web.-f730bbd9-e80e-475a-9d8d-885639a7ff4a

@wkloucek
Copy link
Contributor

@refs Do you have an idea? I'm pretty clueless

@refs
Copy link
Member

refs commented Jun 23, 2021

I have not dug into why it does work with the brackets, but have ran into this error when ipv6 is enabled in my machine. Reading up in your link to the docs I see why it works with brackets:

If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or "[fe80::1%zone]:80".

I pretty much think the logic is assuming too much and treats ipv4 as ipv6 (as in: tcp.Dial("::1:9505") -> this is invalid). A simple guard should suffice and provide support out of the box to both ipv4 and ipv6.

@refs
Copy link
Member

refs commented Jun 23, 2021

I'm confused as to how 0.0.0.0 gets translated into ::1. We're basically handing over the address to go-micro: https://github.com/owncloud/ocis/blob/dc932c690487118ed7c0cbd0911856975289da72/proxy/pkg/server/http/server.go#L50 without any transformation.

@wkloucek
Copy link
Contributor

wkloucek commented Jun 23, 2021

0.0.0.0 and [::0] have the same meaning: bind to all available interfaces.

These also include 127.0.0.1 and [::1] (localhost). This is the theory. But in reality our binary (somewhere deep down in the chain) uses ::1 only as IPV6 localhost, but I couldn't find the point where it will be translated.

@refs
Copy link
Member

refs commented Jun 23, 2021

I believe it is in go-micro. I'll do some digging and keep us in the loop 👍

@refs
Copy link
Member

refs commented Jun 23, 2021

@wkloucek the corresponding go-micro line that logs is:

2021-06-23 12:50:14 file=v3@v3.0.0-20210408173139-0d57213d3f5c/http.go:255 level=info Listening on [::]:1111

digging into go-micro for the version 0d57213d3f5c: https://github.com/asim/go-micro/blob/4c1f81dadb47b90f71f37c4f845af5821ef80a47/plugins/server/http/http.go#L255

that listener contains the following information (when ipv6 is enabled):

image

that gets parsed as:

image

Digging into the lowest level we find this syscall:

if supportsIPv4map() && family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW {
// Allow both IP versions even if the OS default
// is otherwise. Note that some operating systems
// never admit this option.
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only))
}

where the condition evaluates to true, sets the socket options to IPv6. By this time the fd does not have any address set, this is acquired here:

...
fd.setAddr(fd.addrFunc()(lsa), nil)
...

in sock_posix.go from the stdlib.

and ultimately sets the address to an ipv6 address:

func sockaddrToTCP(sa syscall.Sockaddr) Addr {
	switch sa := sa.(type) {
	case *syscall.SockaddrInet4:
		return &TCPAddr{IP: sa.Addr[0:], Port: sa.Port}
	case *syscall.SockaddrInet6:
		return &TCPAddr{IP: sa.Addr[0:], Port: sa.Port, Zone: zoneCache.name(int(sa.ZoneId))}
	}
	return nil
}

At least in my system.

Now, debugging session apart, with ipv6 enabled in my system, I cannot reproduce @labkode's issue:

image

And sub-sequentially running:

bin/wopiserver server --http-addr "[::1]:1111"
bin/wopiserver server --http-addr "[0.0.0.0]:1111"
bin/wopiserver server --http-addr "[::0]:1111"

work for me.

@refs
Copy link
Member

refs commented Jun 23, 2021

I'm running on go version go1.16.2 darwin/amd64

@refs
Copy link
Member

refs commented Jun 23, 2021

I'm, however, able to reproduce something similar under this circumstances:

  1. disable ipv6 in my system
  2. run bin/wopiserver server --http-addr ::1:1111

that throws

{
   "level":"error",
   "service":"wopiserver",
   "error":"listen tcp: address ::1:1111: too many colons in address",
   "transport":"http",
   "time":"2021-06-23T13:41:28+02:00",
   "message":"Failed to start server"
}

@wkloucek
Copy link
Contributor

this project is depreciated and will be archived

the same error is tracked in oCIS: owncloud/ocis#2300

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
OCIS-Fastlane Planned outside of the sprint
Projects
None yet
Development

No branches or pull requests

4 participants