coreos/etcd — pull request #270 by mattcottingham (2013-10-22 09:47:56+00:00)
Title: Update go-systemd packages to fix panic

Compiling etcd with Go 1.2rc2 exposed some behaviour which I have been unable to replicate with Go 1.1.2.

```
$ go version
go version go1.2rc2 linux/amd64
$ ./build
$ ./etcd -d node0 -n node0
[etcd] Oct 22 10:32:30.694 INFO | Found node configuration in 'node0/info'. Ignoring flags
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x54c007]

goroutine 1 [running]:
runtime.panic(0x71ef00, 0xbc5788)
/usr/local/src/go/src/pkg/runtime/panic.c:266 +0xb6
net.(*UnixConn).Write(0x0, 0xc21009f000, 0x104, 0x192, 0xbcc560, ...)
/usr/local/src/go/src/pkg/net/dial.go:1 +0x17
bytes.(*Buffer).WriteTo(0xc210052540, 0x7f64dc4a1bb0, 0x0, 0x0, 0x0, ...)
/usr/local/src/go/src/pkg/bytes/buffer.go:202 +0xc5
io.Copy(0x7f64dc4a1bb0, 0x0, 0x7f64dc4a1b88, 0xc210052540, 0x0, ...)
/usr/local/src/go/src/pkg/io/io.go:344 +0xa5
github.com/coreos/go-systemd/journal.Send(0xc210051980, 0x38, 0x6, 0xc21009a180, 0xc21001ea01, ...)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/go-systemd/journal/send.go:62 +0x2d0
github.com/coreos/go-log/log.(*journalSink).Log(0xbd6530, 0xc21009a150)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/go-log/log/sinks.go:84 +0x228
github.com/coreos/go-log/log.(*combinedSink).Log(0xc21004b580, 0xc21009a150)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/go-log/log/sinks.go:121 +0x67
github.com/coreos/go-log/log.(*Logger).Log(0xc2100504e0, 0x6, 0x7f64dc471aa0, 0x1, 0x1)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/go-log/log/commands.go:37 +0x14e
github.com/coreos/go-log/log.(*Logger).Infof(0xc2100504e0, 0x80f250, 0x30, 0x7f64dc471bb0, 0x1, ...)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/go-log/log/commands.go:92 +0xfc
main.infof(0x80f250, 0x30, 0x7f64dc471bb0, 0x1, 0x1)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/etcd/util.go:178 +0x5c
main.getInfo(0x7fffae224342, 0x5, 0xc2000001e4)
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/etcd/config.go:49 +0x79b
main.main()
/home/matt/dev/go/src/github.com/coreos/etcd/src/github.com/coreos/etcd/etcd.go:224 +0x75d

goroutine 3 [runnable]:
os/signal.loop()
/usr/local/src/go/src/pkg/os/signal/signal_unix.go:19
created by os/signal.init·1
/usr/local/src/go/src/pkg/os/signal/signal_unix.go:27 +0x31

```

With Go 1.1.2, this panic does not occur:

```
$ go version
go version go1.1.2 linux/amd64
$ ./build
$ ./etcd -d node0 -n node0
[etcd] Oct 22 10:36:05.995 INFO | Found node configuration in 'node0/info'. Ignoring flags
[etcd] Oct 22 10:36:05.996 WARNING | the entire cluster is down! this machine will restart the cluster.
[etcd] Oct 22 10:36:05.996 INFO | etcd server [name node0, listen on 127.0.0.1:4001, advertised url http://127.0.0.1:4001]
[etcd] Oct 22 10:36:05.996 INFO | raft server [name node0, listen on 127.0.0.1:7001, advertised url http://127.0.0.1:7001]
^C
```

I was able to fix the panic by updating third_party/coreos/go-systemd to the latest version (af0e6cd015e5fad8d9d090ad7aa343a1f680318d). The relevant commit is probably https://github.com/coreos/go-systemd/commit/3a065f53e80d56dbce94e501e523ffad15bae44b which checks whether `net.Dial` succeeds.

With the updated go-systemd packages:

```
$ go version
go version go1.2rc2 linux/amd64
$ ./build
$ ./etcd -d node0 -n node0
[etcd] Oct 22 10:43:39.197 INFO | Found node configuration in 'node0/info'. Ignoring flags
[etcd] Oct 22 10:43:39.199 WARNING | the entire cluster is down! this machine will restart the cluster.
[etcd] Oct 22 10:43:39.199 INFO | etcd server [name node0, listen on 127.0.0.1:4001, advertised url http://127.0.0.1:4001]
[etcd] Oct 22 10:43:39.200 INFO | raft server [name node0, listen on 127.0.0.1:7001, advertised url http://127.0.0.1:7001]
^C
```

All tests pass.

The thing I haven't had time to investigate is what's changed between Go 1.1.2 and the release candidate to cause this change in behaviour. But since there's now a feature freeze we can probably safely assume this fix will apply to Go 1.2 as well.

At the moment I've cloned `go-systemd` and removed `.git`: perhaps it would be easier for future updates to use git submodules for third party sources?