-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from splitio/enh/dead_socket_removal_attempt
attempt to remove dead socket on startup
- Loading branch information
Showing
16 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package splitio | ||
|
||
const CommitSHA = "29ff22d" | ||
const CommitSHA = "a41bede" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,64 @@ | ||
package transfer | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/splitio/go-toolkit/v5/logging" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConnType(t *testing.T) { | ||
assert.Equal(t, "unix-seqpacket", ConnTypeUnixSeqPacket.String()) | ||
assert.Equal(t, "unix-stream", ConnTypeUnixStream.String()) | ||
assert.Equal(t, "invalid-socket-type", ConnType(123).String()) | ||
} | ||
|
||
func TestEnsureAddressIsUsable(t *testing.T) { | ||
|
||
logger := logging.NewLogger(nil) | ||
assert.Nil(t, ensureAddressUsable(logger, &net.UDPAddr{})) | ||
assert.Nil(t, ensureAddressUsable(logger, &net.TCPAddr{})) | ||
assert.Nil(t, ensureAddressUsable(logger, &net.UnixAddr{Name: "/some/nonexistent/file"})) | ||
|
||
// test unknown error (in this case trying to connect to a different socket type) | ||
ready := make(chan struct{}) | ||
path := filepath.Join(os.TempDir(), "splitd_test_ensure_address_usable.sock") | ||
os.Remove(path) // por las dudas | ||
go func() { | ||
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"}) | ||
assert.Nil(t, err) | ||
defer l.Close() | ||
|
||
l.SetDeadline(time.Now().Add(1 * time.Second)) | ||
go func() { | ||
time.Sleep(100 * time.Millisecond) | ||
ready <- struct{}{} | ||
}() | ||
l.Accept() | ||
}() | ||
<-ready | ||
assert.ErrorContains(t, ensureAddressUsable(logger, &net.UnixAddr{Name: path, Net: "unixpacket"}), "unknown error when testing for a dead socket") | ||
|
||
// test socket in use error | ||
ready = make(chan struct{}) | ||
path = filepath.Join(os.TempDir(), "splitd_test_ensure_address_usable2.sock") | ||
os.Remove(path) // por las dudas | ||
go func() { | ||
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"}) | ||
assert.Nil(t, err) | ||
defer l.Close() | ||
|
||
l.SetDeadline(time.Now().Add(1 * time.Second)) | ||
go func() { | ||
time.Sleep(100 * time.Millisecond) | ||
ready <- struct{}{} | ||
}() | ||
l.Accept() | ||
}() | ||
<-ready | ||
assert.ErrorIs(t, ErrServiceAddressInUse, ensureAddressUsable(logger, &net.UnixAddr{Name: path, Net: "unix"})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package profiler | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/pprof" | ||
) | ||
|
||
func init() { | ||
http.DefaultServeMux = http.NewServeMux() | ||
} | ||
|
||
type HTTPProfileInterface struct { | ||
server http.Server | ||
//server http.ServeMux | ||
} | ||
|
||
func New(host string, port int) *HTTPProfileInterface { | ||
mux := http.NewServeMux() | ||
|
||
mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) | ||
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) | ||
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) | ||
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) | ||
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) | ||
return &HTTPProfileInterface{ | ||
http.Server{ | ||
Addr: fmt.Sprintf("%s:%d", host, port), | ||
Handler: mux, | ||
}, | ||
} | ||
} | ||
|
||
func (h *HTTPProfileInterface) ListenAndServe() error { | ||
return h.server.ListenAndServe() | ||
} |
Oops, something went wrong.