@@ -10,6 +10,7 @@ import (
10
10
"path"
11
11
"path/filepath"
12
12
"sync"
13
+ "sync/atomic"
13
14
"time"
14
15
15
16
"github.com/gorilla/websocket"
@@ -84,7 +85,7 @@ func (s Sync) initSync() error {
84
85
85
86
start := time .Now ()
86
87
// Delete old files on initial sync (e.g git checkout).
87
- err := s .syncPaths (true , s .LocalDir + "/." , s .RemoteDir )
88
+ err := s .syncPaths (true , s .LocalDir + "/." , s .RemoteDir )
88
89
if err == nil {
89
90
flog .Info ("finished initial sync (%v)" , time .Since (start ).Truncate (time .Millisecond ))
90
91
}
@@ -167,7 +168,6 @@ func (s Sync) work(ev timedEvent) {
167
168
}
168
169
}
169
170
170
-
171
171
var ErrRestartSync = errors .New ("the sync exited because it was overloaded, restart it" )
172
172
173
173
// workEventGroup converges a group of events to prevent duplicate work.
@@ -239,14 +239,21 @@ func (s Sync) Run() error {
239
239
240
240
flog .Info ("watching %s for changes" , s .LocalDir )
241
241
242
+ var droppedEvents uint64
242
243
// Timed events lets us track how long each individual file takes to update.
243
244
timedEvents := make (chan timedEvent , cap (events ))
244
245
go func () {
245
246
defer close (timedEvents )
246
247
for event := range events {
247
- timedEvents <- timedEvent {
248
+ select {
249
+ case timedEvents <- timedEvent {
248
250
CreatedAt : time .Now (),
249
251
EventInfo : event ,
252
+ }:
253
+ default :
254
+ if atomic .AddUint64 (& droppedEvents , 1 ) == 1 {
255
+ flog .Info ("dropped event, sync should restart soon" )
256
+ }
250
257
}
251
258
}
252
259
}()
@@ -262,7 +269,7 @@ func (s Sync) Run() error {
262
269
263
270
select {
264
271
case ev := <- timedEvents :
265
- if len ( events ) > maxInflightInotify {
272
+ if atomic . LoadUint64 ( & droppedEvents ) > 0 {
266
273
return ErrRestartSync
267
274
}
268
275
0 commit comments