From 86aa452d3c604857eb263cef7dcc22b04579a328 Mon Sep 17 00:00:00 2001 From: Valentyn Kahamlyk Date: Thu, 11 Jan 2024 17:02:29 -0800 Subject: [PATCH] ... --- gremlin-go/driver/resultSet.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gremlin-go/driver/resultSet.go b/gremlin-go/driver/resultSet.go index 0a1309643df..5d6f8d212c1 100644 --- a/gremlin-go/driver/resultSet.go +++ b/gremlin-go/driver/resultSet.go @@ -56,6 +56,7 @@ type channelResultSet struct { waitSignal chan bool channelMutex sync.Mutex waitSignalMutex sync.Mutex + errorMutex sync.Mutex } func (channelResultSet *channelResultSet) sendSignal() { @@ -70,10 +71,14 @@ func (channelResultSet *channelResultSet) sendSignal() { // GetError returns error from the channelResultSet. func (channelResultSet *channelResultSet) GetError() error { + channelResultSet.errorMutex.Lock() + defer channelResultSet.errorMutex.Unlock() return channelResultSet.err } func (channelResultSet *channelResultSet) setError(err error) { + channelResultSet.errorMutex.Lock() + defer channelResultSet.errorMutex.Unlock() channelResultSet.err = err } @@ -166,13 +171,14 @@ func (channelResultSet *channelResultSet) Channel() chan *Result { // The value of ok is true if the value received was delivered by a successful send operation to the channel, // or false if it is a zero value generated because the channel is closed and empty. func (channelResultSet *channelResultSet) One() (*Result, bool, error) { - err := channelResultSet.err + err := channelResultSet.GetError() if err != nil { - return nil, false, channelResultSet.err + return nil, false, err } result, ok := <-channelResultSet.channel - if channelResultSet.err != nil { - return nil, false, channelResultSet.err + err = channelResultSet.GetError() + if err != nil { + return nil, false, err } return result, ok, nil } @@ -183,7 +189,7 @@ func (channelResultSet *channelResultSet) All() ([]*Result, error) { for result := range channelResultSet.channel { results = append(results, result) } - return results, channelResultSet.err + return results, channelResultSet.GetError() } func (channelResultSet *channelResultSet) addResult(r *Result) { @@ -206,7 +212,7 @@ func (channelResultSet *channelResultSet) addResult(r *Result) { } func newChannelResultSetCapacity(requestID string, container *synchronizedMap, channelSize int) ResultSet { - return &channelResultSet{make(chan *Result, channelSize), requestID, container, "", nil, false, nil, nil, sync.Mutex{}, sync.Mutex{}} + return &channelResultSet{make(chan *Result, channelSize), requestID, container, "", nil, false, nil, nil, sync.Mutex{}, sync.Mutex{}, sync.Mutex{}} } func newChannelResultSet(requestID string, container *synchronizedMap) ResultSet {