From 8797ec7f10d291b8618e8920fffe7cbea68bb53f Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Fri, 8 Nov 2024 13:51:10 -0600 Subject: [PATCH] Nil-safe topo.lock Signed-off-by: Florent Poinsard --- go/vt/topo/locks.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/go/vt/topo/locks.go b/go/vt/topo/locks.go index 719be66655d..967d3f7f2e4 100644 --- a/go/vt/topo/locks.go +++ b/go/vt/topo/locks.go @@ -19,6 +19,7 @@ package topo import ( "context" "encoding/json" + "errors" "os" "os/user" "sync" @@ -158,9 +159,6 @@ type iTopoLock interface { // perform the topo lock operation func (l *Lock) lock(ctx context.Context, ts *Server, lt iTopoLock, opts ...LockOption) (LockDescriptor, error) { - if err := ctx.Err(); err != nil { - return nil, err - } for _, o := range opts { o.apply(&l.Options) } @@ -178,6 +176,12 @@ func (l *Lock) lock(ctx context.Context, ts *Server, lt iTopoLock, opts ...LockO return nil, err } + if err := ctx.Err(); err != nil { + return nil, err + } + if ts.globalCell == nil { + return nil, errors.New("no global cell connection on the topo server") + } switch l.Options.lockType { case NonBlocking: return ts.globalCell.TryLock(ctx, lt.Path(), j)