diff options
author | Wolfy-J <[email protected]> | 2019-12-23 15:20:57 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-12-23 15:20:57 +0300 |
commit | d39e20a58c8a40eefe6e5d6761f78f38f024b46e (patch) | |
tree | cd4f7f514cc1b735bef07f0228e7f41bf52c5d8d | |
parent | 1d225f1e88d176c955111d2a033ab0f14834f93e (diff) |
- check before erasing unix sock
-rw-r--r-- | pipe_factory_test.go | 1 | ||||
-rw-r--r-- | server_config.go | 12 | ||||
-rw-r--r-- | server_config_test.go | 4 | ||||
-rw-r--r-- | worker.go | 9 |
4 files changed, 15 insertions, 11 deletions
diff --git a/pipe_factory_test.go b/pipe_factory_test.go index 08c47d94..27d1f74d 100644 --- a/pipe_factory_test.go +++ b/pipe_factory_test.go @@ -14,7 +14,6 @@ func Test_Pipe_Start(t *testing.T) { assert.NotNil(t, w) go func() { - assert.NoError(t, w.Wait()) }() diff --git a/server_config.go b/server_config.go index 641c1866..5403ff01 100644 --- a/server_config.go +++ b/server_config.go @@ -127,7 +127,7 @@ func (cfg *ServerConfig) makeFactory() (Factory, error) { return nil, errors.New("invalid relay DSN (pipes, tcp://:6001, unix://rr.sock)") } - if dsn[0] == "unix" { + if dsn[0] == "unix" && fileExists(dsn[1]) { err := syscall.Unlink(dsn[1]) if err != nil { return nil, err @@ -141,3 +141,13 @@ func (cfg *ServerConfig) makeFactory() (Factory, error) { return NewSocketFactory(ln, cfg.RelayTimeout), nil } + +// fileExists checks if a file exists and is not a directory before we +// try using it to prevent further errors. +func fileExists(filename string) bool { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() +} diff --git a/server_config_test.go b/server_config_test.go index 4f26d6ab..303eba90 100644 --- a/server_config_test.go +++ b/server_config_test.go @@ -71,6 +71,10 @@ func Test_ServerConfig_UnixSocketFactory(t *testing.T) { cfg := &ServerConfig{Relay: "unix://unix.sock"} f, err := cfg.makeFactory() + if err != nil { + t.Error(err) + } + defer func() { err := f.Close() if err != nil { @@ -6,7 +6,6 @@ import ( "github.com/spiral/goridge" "os" "os/exec" - "runtime" "strconv" "strings" "sync" @@ -102,14 +101,6 @@ func (w *Worker) Wait() error { w.mu.Lock() defer w.mu.Unlock() - if runtime.GOOS != "windows" { - // windows handles processes and close pipes differently, - // we can ignore wait here as process.Wait() already being handled above - if err := w.cmd.Wait(); err != nil { - return err - } - } - if w.endState.Success() { w.state.set(StateStopped) return nil |