File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,7 @@ func (cr *Cluster) Connect(ctx context.Context) bool {
306
306
logErrorf ("Dial error: %v" , err )
307
307
return false
308
308
}
309
+ logInfo ("Connecting to socket.io namespace" )
309
310
if err := cr .socket .Connect ("" ); err != nil {
310
311
logErrorf ("Open namespace error: %v" , err )
311
312
return false
@@ -440,7 +441,7 @@ func (cr *Cluster) disconnected() bool {
440
441
cr .mux .Lock ()
441
442
defer cr .mux .Unlock ()
442
443
443
- if ! cr .enabled .Swap ( false ) {
444
+ if cr .enabled .CompareAndSwap ( true , false ) {
444
445
return false
445
446
}
446
447
if cr .cancelKeepalive != nil {
@@ -669,7 +670,7 @@ type syncStats struct {
669
670
670
671
func (cr * Cluster ) SyncFiles (ctx context.Context , files []FileInfo , heavyCheck bool ) bool {
671
672
logInfo ("Preparing to sync files..." )
672
- if cr .issync .Swap ( true ) {
673
+ if ! cr .issync .CompareAndSwap ( false , true ) {
673
674
logWarn ("Another sync task is running!" )
674
675
return false
675
676
}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"net/http"
28
28
"net/url"
29
29
"strconv"
30
+ "sync/atomic"
30
31
"time"
31
32
)
32
33
@@ -39,6 +40,7 @@ type httpTLSListener struct {
39
40
TLSConfig * tls.Config
40
41
hosts []string
41
42
43
+ accepting atomic.Bool
42
44
acceptedCh chan net.Conn
43
45
errCh chan error
44
46
}
@@ -126,15 +128,16 @@ READ_HEAD:
126
128
}
127
129
128
130
func (s * httpTLSListener ) accepter () {
129
- for {
131
+ for s . accepting . CompareAndSwap ( false , true ) {
130
132
conn , err := s .Listener .Accept ()
133
+ s .accepting .Store (false )
131
134
if err != nil {
132
135
s .errCh <- err
133
136
return
134
137
}
135
- // TODO: start another accepter while reading this one
138
+ go s . accepter ()
136
139
hr := & connHeadReader {Conn : conn }
137
- hr .SetReadDeadline (time .Now ().Add (time .Second ))
140
+ hr .SetReadDeadline (time .Now ().Add (time .Second * 5 ))
138
141
if ! s .maybeRedirectConn (hr ) {
139
142
hr .SetReadDeadline (time.Time {})
140
143
// if it's not a http connection, try it with tls and return
You can’t perform that action at this time.
0 commit comments