From 61b9dd953e968eeb44d56f7a1edef135f711918c Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Mon, 2 Nov 2020 22:42:48 +0530 Subject: [PATCH] fix(worker): Avoid panic in handleUidPostings (#6607) (#6700) Fixes DGRAPH-2491 (cherry picked from commit f77cfe34ebd289806097b682a78bb4952cb2e0eb) Co-authored-by: Harshil Goel <54325286+harshil-goel@users.noreply.github.com> --- worker/task.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/worker/task.go b/worker/task.go index 669a35cb438..a07905fbe52 100644 --- a/worker/task.go +++ b/worker/task.go @@ -687,6 +687,18 @@ func (qs *queryState) handleUidPostings( return nil } + // srcFn.n should be equal to len(q.UidList.Uids) for below implementation(DivideAndRule and + // calculate) to work correctly. But we have seen some panics while forming DataKey in + // calculate(). panic is of the form "index out of range [4] with length 1". Hence return error + // from here when srcFn.n != len(q.UidList.Uids). + switch srcFn.fnType { + case notAFunction, compareScalarFn, hasFn, uidInFn: + if srcFn.n != len(q.UidList.GetUids()) { + return errors.Errorf("srcFn.n: %d is not equal to len(q.UidList.Uids): %d, srcFn: %+v in "+ + "handleUidPostings", srcFn.n, len(q.UidList.GetUids()), srcFn) + } + } + // Divide the task into many goroutines. numGo, width := x.DivideAndRule(srcFn.n) x.AssertTrue(width > 0)