Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ run:
linters:
default: none
enable:
- misspell
- govet
- ineffassign
- misspell
- noctx
- revive
- unconvert
- unused
- govet
settings:
govet:
enable:
Expand Down
4 changes: 2 additions & 2 deletions agent/testutils/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ func NewMockDispatcher(t *testing.T, secConfig *ca.SecurityConfig, local bool) (
tempDir, err := os.MkdirTemp("", "local-dispatcher-socket")
require.NoError(t, err)
addr = filepath.Join(tempDir, "socket")
l, err = net.Listen("unix", addr)
l, err = (&net.ListenConfig{}).Listen(t.Context(), "unix", addr)
require.NoError(t, err)
cleanup = func() {
os.RemoveAll(tempDir)
}
} else {
l, err = net.Listen("tcp", "127.0.0.1:0")
l, err = (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0")
require.NoError(t, err)
addr = l.Addr().String()
}
Expand Down
2 changes: 1 addition & 1 deletion ca/testutils/cautils.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func newTestCA(t *testing.T, tempBaseDir string, apiRootCA api.RootCA, krwGenera
assert.NoError(t, err)
}

l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0")
if t != nil {
assert.NoError(t, err)
}
Expand Down
4 changes: 2 additions & 2 deletions ca/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *MutableTLSCreds) ClientHandshake(ctx context.Context, addr string, rawC
var err error
errChannel := make(chan error, 1)
go func() {
errChannel <- conn.Handshake()
errChannel <- conn.HandshakeContext(context.Background())
}()
select {
case err = <-errChannel:
Expand All @@ -106,7 +106,7 @@ func (c *MutableTLSCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentia
c.Lock()
conn := tls.Server(rawConn, c.config)
c.Unlock()
if err := conn.Handshake(); err != nil {
if err := conn.HandshakeContext(context.Background()); err != nil {
rawConn.Close()
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/swarm-bench/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Collector struct {
// once they come online.
func (c *Collector) Listen(port int) error {
var err error
c.ln, err = net.Listen("tcp", ":"+strconv.Itoa(port))
c.ln, err = (&net.ListenConfig{}).Listen(context.Background(), "tcp", ":"+strconv.Itoa(port))
return err
}

Expand Down
3 changes: 2 additions & 1 deletion connectionbroker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package connectionbroker

import (
"context"
"net"
"sync"
"time"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (b *Broker) SelectRemote(dialOpts ...grpc.DialOption) (*Conn, error) {
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor),
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("tcp", addr, timeout)
return (&net.Dialer{Timeout: timeout}).DialContext(context.Background(), "tcp", addr)
}))

cc, err := grpc.Dial(peer.Addr, dialOpts...)
Expand Down
2 changes: 1 addition & 1 deletion manager/controlapi/ca_rotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func validateExternalCAURL(dialer *net.Dialer, tlsOpts *tls.Config, caURL string
port = "443"
}

conn, err := tls.DialWithDialer(dialer, "tcp", net.JoinHostPort(host, port), tlsOpts)
conn, err := (&tls.Dialer{NetDialer: dialer, Config: tlsOpts}).DialContext(context.Background(), "tcp", net.JoinHostPort(host, port))
if conn != nil {
conn.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (m *Manager) BindRemote(ctx context.Context, addrs RemoteAddrs) error {
advertiseAddr = net.JoinHostPort("0.0.0.0", advertiseAddrPort)
}

l, err := net.Listen("tcp", addrs.ListenAddr)
l, err := (&net.ListenConfig{}).Listen(context.Background(), "tcp", addrs.ListenAddr)
if err != nil {
return errors.Wrap(err, "failed to listen on remote API address")
}
Expand Down
2 changes: 1 addition & 1 deletion manager/state/raft/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ var _ raft.EncryptionKeyRotator = NewSimpleKeyRotator(raft.EncryptionKeys{})

// NewNode creates a new raft node to use for tests
func NewNode(t *testing.T, clockSource *fakeclock.FakeClock, tc *cautils.TestCA, opts ...raft.NodeOptions) *TestNode {
l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0")
require.NoError(t, err, "can't bind to raft service port")
wrappedListener := NewWrappedListener(l)

Expand Down
2 changes: 1 addition & 1 deletion manager/state/raft/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (t *Transport) dial(addr string) (*grpc.ClientConn, error) {
// TODO(anshul) Add an option to configure this.
grpcOptions = append(grpcOptions,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("tcp", addr, timeout)
return (&net.Dialer{Timeout: timeout}).DialContext(context.Background(), "tcp", addr)
}))

// TODO(dperny): this changes the max received message size for outgoing
Expand Down
2 changes: 1 addition & 1 deletion manager/state/raft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func dial(addr string, _ string, creds credentials.TransportCredentials, timeout
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor),
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("tcp", addr, timeout)
return (&net.Dialer{Timeout: timeout}).DialContext(context.Background(), "tcp", addr)
}),
}

Expand Down
5 changes: 3 additions & 2 deletions xnet/xnet_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
package xnet

import (
"context"
"net"
"time"
)

// ListenLocal opens a local socket for control communication
func ListenLocal(socket string) (net.Listener, error) {
// on unix it's just a unix socket
return net.Listen("unix", socket)
return (&net.ListenConfig{}).Listen(context.Background(), "unix", socket)
}

// DialTimeoutLocal is a DialTimeout function for local sockets
func DialTimeoutLocal(socket string, timeout time.Duration) (net.Conn, error) {
// on unix, we dial a unix socket
return net.DialTimeout("unix", socket, timeout)
return (&net.Dialer{Timeout: timeout}).DialContext(context.Background(), "unix", socket)
}