-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix locking in getConnection #288
Conversation
Signed-off-by: Henry Robinson <[email protected]>
Signed-off-by: Henry Robinson <[email protected]>
Signed-off-by: Henry Robinson <[email protected]>
proxy.mu.Lock() | ||
defer proxy.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops much better thanks.
But I think we still need the RUnlock() because IIRC you can't "promote" a RWLock without first dropping the read lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's still there - just moved above the log / error checking logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG duuuh.
grpcclient.RegisterGRPCDialOptions(func(opts []grpc.DialOption) ([]grpc.DialOption, error) { | ||
return append(opts, grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`)), nil | ||
}) | ||
// Check again in case conn was made between lock acquisitions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also very good idea, thanks.
|
||
// Otherwise create a new connection. TODO: confirm this doesn't actually make a TCP connection, and returns quickly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure it does not. There's a WithBlock thing that IIRC you can pass to make this blocking, but if not then it is non-blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya - confirmed, the model in grpc is pretty weird, you create a "conn", but that's basically just a handle to make RPC requests. It's not until you make an RPC call that it will actually start mapping the RPC to a subconn (which maps to a TCP connection).
That's also why you can reuse the conn - it should represent a logical target to send the RPC commands to.
@@ -174,4 +179,8 @@ func (proxy *VTGateProxy) StreamExecute(ctx context.Context, session *vtgateconn | |||
} | |||
|
|||
func Init() { | |||
log.V(100).Infof("Registering GRPC dial options") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eek - I think demmer and I talked about this and never fixed it - thank you for moving this here and doing it once!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep looks great to me.
* Fix locking in getConnection Signed-off-by: Henry Robinson <[email protected]> * Comment Signed-off-by: Henry Robinson <[email protected]> * Undo bash change Signed-off-by: Henry Robinson <[email protected]> --------- Signed-off-by: Henry Robinson <[email protected]>
* Fix locking in getConnection Signed-off-by: Henry Robinson <[email protected]> * Comment Signed-off-by: Henry Robinson <[email protected]> * Undo bash change Signed-off-by: Henry Robinson <[email protected]> --------- Signed-off-by: Henry Robinson <[email protected]>
* Fix locking in getConnection Signed-off-by: Henry Robinson <[email protected]> * Comment Signed-off-by: Henry Robinson <[email protected]> * Undo bash change Signed-off-by: Henry Robinson <[email protected]> --------- Signed-off-by: Henry Robinson <[email protected]>
* Fix locking in getConnection Signed-off-by: Henry Robinson <[email protected]> * Comment Signed-off-by: Henry Robinson <[email protected]> * Undo bash change Signed-off-by: Henry Robinson <[email protected]> --------- Signed-off-by: Henry Robinson <[email protected]>
Unlock
if an error happens when creating a connection