Permalink
Browse files

Fix gonit unix socket bug.

If gonit started the RPC server listener and then unexpectedly
shutdown, it would not clean up the unix socket file.  When gonit
was restarted it would then fail to start due to the unix socket file
already existing.

Change-Id: I05b70cff2956e785602fac699b36a2a0e86faf84
  • Loading branch information...
lisbakke committed Sep 25, 2012
1 parent 5223264 commit 81ee759c32016bc417513e8f03eb6b859b11ab6e
Showing with 4 additions and 11 deletions.
  1. +3 −0 rpc.go
  2. +1 −11 rpc_test.go
View
3 rpc.go
@@ -36,6 +36,9 @@ func NewRpcServer(listenURL string) (*RpcServer, error) {
listener, err = net.Listen("tcp", url.Host)
}
case "", "unix":
+ // If the file already exists, we need to remove it otherwise gonit can't
+ // start.
+ os.Remove(url.Path)
listener, err = net.Listen("unix", url.Path)
cleanup = func() { os.Remove(url.Path) }
default:
View
@@ -9,7 +9,6 @@ import (
"net/rpc"
"net/rpc/jsonrpc"
"os"
- "syscall"
"testing"
)
@@ -45,19 +44,10 @@ func TestUnixServer(t *testing.T) {
server, err := NewRpcServer(url)
- // expected when file already exists
- assert.NotEqual(t, nil, err)
- assert.Equal(t, syscall.EADDRINUSE, err.(*net.OpError).Err)
-
- os.Remove(path)
- fi, err := os.Stat(path) // double check file is gone
- assert.NotEqual(t, nil, err)
-
- server, err = NewRpcServer(url)
assert.Equal(t, nil, err)
// check file exists and is a unix socket
- fi, err = os.Stat(path)
+ fi, err := os.Stat(path)
assert.Equal(t, nil, err)
assert.Equal(t, os.ModeSocket, fi.Mode()&os.ModeSocket)

0 comments on commit 81ee759

Please sign in to comment.