From ffab8e6d409fa0499aadfee1bbf372c3af21620e Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Mon, 29 Oct 2018 18:01:07 -0700 Subject: [PATCH] Addressing race conditions that may happen when client is closed or connection is re-established. --- realis.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/realis.go b/realis.go index f934565..72f5624 100644 --- a/realis.go +++ b/realis.go @@ -443,7 +443,7 @@ func newTJSONConfig(url string, timeoutms int, config *RealisConfig) (*RealisCon httpTrans := (trans).(*thrift.THttpClient) 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 } @@ -460,7 +460,7 @@ func newTBinaryConfig(url string, timeoutms int, config *RealisConfig) (*RealisC httpTrans.SetHeader("Accept", "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 @@ -476,6 +476,9 @@ func (r *realisClient) ReestablishConn() error { r.logger.Println("Re-establishing Connection to Aurora") r.Close() + r.lock.Lock() + defer r.lock.Unlock() + // Recreate connection from scratch using original options newRealis, err := NewRealisClient(r.config.options...) if err != nil { @@ -498,6 +501,10 @@ func (r *realisClient) ReestablishConn() error { // Releases resources associated with the realis client. func (r *realisClient) Close() { + + r.lock.Lock() + defer r.lock.Unlock() + r.client.Transport.Close() r.readonlyClient.Transport.Close() r.adminClient.Transport.Close()