File tree 2 files changed +7
-2
lines changed
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,8 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
276
276
return xerrors .Errorf ("ping database: %w" , err )
277
277
}
278
278
279
+ m .mutex .Lock ()
280
+ defer m .mutex .Unlock ()
279
281
replica , err := m .db .UpdateReplica (ctx , database.UpdateReplicaParams {
280
282
ID : m .self .ID ,
281
283
UpdatedAt : database .Now (),
@@ -291,8 +293,6 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
291
293
if err != nil {
292
294
return xerrors .Errorf ("update replica: %w" , err )
293
295
}
294
- m .mutex .Lock ()
295
- defer m .mutex .Unlock ()
296
296
if m .self .Error != replica .Error {
297
297
// Publish an update occurred!
298
298
err = m .pubsub .Publish (PubsubEvent , []byte (m .self .ID .String ()))
Original file line number Diff line number Diff line change @@ -206,7 +206,12 @@ func TestReplica(t *testing.T) {
206
206
_ = server .Close ()
207
207
})
208
208
done := false
209
+
210
+ var m sync.Mutex
209
211
server .SetCallback (func () {
212
+ m .Lock ()
213
+ defer m .Unlock ()
214
+
210
215
if len (server .All ()) != count {
211
216
return
212
217
}
You can’t perform that action at this time.
0 commit comments