From db6c36c75f64d2f6d92f6ef5b810b96ce6a42f09 Mon Sep 17 00:00:00 2001 From: Feng Liyuan Date: Thu, 15 Aug 2019 15:21:09 +0800 Subject: [PATCH] executor: fix data race in `(*HashJoinExec).Close()` since `fetchInnerAndBuildHashTable` is still running --- executor/join.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/executor/join.go b/executor/join.go index d9469d32a933a..2b3eae1d5d06e 100644 --- a/executor/join.go +++ b/executor/join.go @@ -541,8 +541,13 @@ func (e *HashJoinExec) fetchInnerAndBuildHashTable(ctx context.Context) { err := e.buildHashTableForList(innerResultCh) if err != nil { e.innerFinished <- errors.Trace(err) + close(doneCh) + } + // Wait fetchInnerRows be finished. + // 1. if buildHashTableForList fails + // 2. if outerResult.NumRows() == 0, fetchOutChunks will not wait for inner. + for range innerResultCh { } - close(doneCh) } // buildHashTableForList builds hash table from `list`.