Commit eadb128 1 parent 2c6e053 commit eadb128 Copy full SHA for eadb128
File tree 2 files changed +5
-2
lines changed
go/vt/vttablet/tabletserver
2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -293,8 +293,10 @@ func (hs *healthStreamer) SetUnhealthyThreshold(v time.Duration) {
293
293
// so it can read and write to the MySQL instance for schema-tracking.
294
294
func (hs * healthStreamer ) MakePrimary (serving bool ) {
295
295
hs .fieldsMu .Lock ()
296
- defer hs .fieldsMu .Unlock ()
297
296
hs .isServingPrimary = serving
297
+ // We let go of the lock here because we don't want to hold the lock when calling RegisterNotifier.
298
+ // If we keep holding the lock, there is a potential deadlock that can happen.
299
+ hs .fieldsMu .Unlock ()
298
300
// We register for notifications from the schema Engine only when schema tracking is enabled,
299
301
// and we are going to a serving primary state.
300
302
if serving && hs .signalWhenSchemaChange {
Original file line number Diff line number Diff line change @@ -592,13 +592,14 @@ func TestDeadlockBwCloseAndReload(t *testing.T) {
592
592
593
593
wg := sync.WaitGroup {}
594
594
wg .Add (2 )
595
- // Try running Close and reload in parallel multiple times.
595
+ // Try running Close & MakePrimary and reload in parallel multiple times.
596
596
// This reproduces the deadlock quite readily.
597
597
go func () {
598
598
defer wg .Done ()
599
599
for i := 0 ; i < 100 ; i ++ {
600
600
hs .Close ()
601
601
hs .Open ()
602
+ hs .MakePrimary (true )
602
603
}
603
604
}()
604
605
You can’t perform that action at this time.
0 commit comments