protect the dialer with a mutex
This commit is contained in:
@ -11,7 +11,7 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
// "sync"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -53,6 +53,7 @@ type Client struct {
|
||||
compression bool
|
||||
|
||||
debug bool
|
||||
mutex sync.Mutex
|
||||
//NEVER, EVER modify lastaddr or id yourself. They are used internally only.
|
||||
id int32
|
||||
sammin int
|
||||
|
3
dial.go
3
dial.go
@ -9,6 +9,8 @@ import (
|
||||
|
||||
// DialContext implements the net.DialContext function and can be used for http.Transport
|
||||
func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
errCh := make(chan error, 1)
|
||||
connCh := make(chan net.Conn, 1)
|
||||
go func() {
|
||||
@ -29,6 +31,7 @@ func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Con
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) Dial(network, addr string) (net.Conn, error) {
|
||||
|
Reference in New Issue
Block a user