protect the dialer with a mutex

This commit is contained in:
idk
2021-04-15 19:16:11 -04:00
parent 460926afe8
commit c6d9c0e340
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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) {