Skip to content

Commit 75718a1

Browse files
committed
Endless query execution fix
1 parent c75ff5f commit 75718a1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

policies.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (host *selectedHost) Info() *HostInfo {
323323
func (host *selectedHost) Mark(err error) {}
324324

325325
// NextHost is an iteration function over picked hosts
326+
// Should return nil if SelectedHost is not Up to prevent endless query execution.
326327
type NextHost func() SelectedHost
327328

328329
// RoundRobinHostPolicy is a round-robin load balancing policy, where each host

query_executor.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,18 @@ func (q *queryExecutor) executeQuery(qry ExecutableQuery) (*Iter, error) {
8989
// check if the host id is specified for the query,
9090
// if it is, the query should be executed at the corresponding host.
9191
if hostID := qry.GetHostID(); hostID != "" {
92+
pool, ok := q.pool.getPoolByHostID(hostID)
93+
if !ok || !pool.host.IsUp() {
94+
return nil, ErrNoConnections
95+
}
96+
host := pool.host
9297
hostIter = func() SelectedHost {
93-
pool, ok := q.pool.getPoolByHostID(hostID)
94-
// if the specified host is down
95-
// we return nil to avoid endless query execution in queryExecutor.do()
96-
if !ok || !pool.host.IsUp() {
97-
return nil
98+
if host != nil {
99+
h := host
100+
host = nil
101+
return (*selectedHost)(h)
98102
}
99-
return (*selectedHost)(pool.host)
103+
return nil
100104
}
101105
}
102106

0 commit comments

Comments
 (0)