Addressing race conditions that may happen when client is closed or connection is re-established.
This commit is contained in:
parent
f37e455852
commit
ffab8e6d40
1 changed files with 9 additions and 2 deletions
11
realis.go
11
realis.go
|
@ -443,7 +443,7 @@ func newTJSONConfig(url string, timeoutms int, config *RealisConfig) (*RealisCon
|
||||||
|
|
||||||
httpTrans := (trans).(*thrift.THttpClient)
|
httpTrans := (trans).(*thrift.THttpClient)
|
||||||
httpTrans.SetHeader("Content-Type", "application/x-thrift")
|
httpTrans.SetHeader("Content-Type", "application/x-thrift")
|
||||||
httpTrans.SetHeader("User-Agent", "GoRealis v"+VERSION)
|
httpTrans.SetHeader("User-Agent", "gorealis v"+VERSION)
|
||||||
|
|
||||||
return &RealisConfig{transport: trans, protoFactory: thrift.NewTJSONProtocolFactory()}, nil
|
return &RealisConfig{transport: trans, protoFactory: thrift.NewTJSONProtocolFactory()}, nil
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ func newTBinaryConfig(url string, timeoutms int, config *RealisConfig) (*RealisC
|
||||||
|
|
||||||
httpTrans.SetHeader("Accept", "application/vnd.apache.thrift.binary")
|
httpTrans.SetHeader("Accept", "application/vnd.apache.thrift.binary")
|
||||||
httpTrans.SetHeader("Content-Type", "application/vnd.apache.thrift.binary")
|
httpTrans.SetHeader("Content-Type", "application/vnd.apache.thrift.binary")
|
||||||
httpTrans.SetHeader("User-Agent", "GoRealis v"+VERSION)
|
httpTrans.SetHeader("User-Agent", "gorealis v"+VERSION)
|
||||||
|
|
||||||
return &RealisConfig{transport: trans, protoFactory: thrift.NewTBinaryProtocolFactoryDefault()}, nil
|
return &RealisConfig{transport: trans, protoFactory: thrift.NewTBinaryProtocolFactoryDefault()}, nil
|
||||||
|
|
||||||
|
@ -476,6 +476,9 @@ func (r *realisClient) ReestablishConn() error {
|
||||||
r.logger.Println("Re-establishing Connection to Aurora")
|
r.logger.Println("Re-establishing Connection to Aurora")
|
||||||
r.Close()
|
r.Close()
|
||||||
|
|
||||||
|
r.lock.Lock()
|
||||||
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
// Recreate connection from scratch using original options
|
// Recreate connection from scratch using original options
|
||||||
newRealis, err := NewRealisClient(r.config.options...)
|
newRealis, err := NewRealisClient(r.config.options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -498,6 +501,10 @@ func (r *realisClient) ReestablishConn() error {
|
||||||
|
|
||||||
// Releases resources associated with the realis client.
|
// Releases resources associated with the realis client.
|
||||||
func (r *realisClient) Close() {
|
func (r *realisClient) Close() {
|
||||||
|
|
||||||
|
r.lock.Lock()
|
||||||
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
r.client.Transport.Close()
|
r.client.Transport.Close()
|
||||||
r.readonlyClient.Transport.Close()
|
r.readonlyClient.Transport.Close()
|
||||||
r.adminClient.Transport.Close()
|
r.adminClient.Transport.Close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue