From 54475e5a5a1744bb30fc2662afaf3f6b11f34c27 Mon Sep 17 00:00:00 2001 From: harshil Date: Wed, 30 Sep 2020 15:49:02 +0530 Subject: [PATCH 1/2] bug(worker): Avoid panic in handleUidPostings --- worker/task.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/worker/task.go b/worker/task.go index 74cc59bcb80..0bc71a4c05e 100644 --- a/worker/task.go +++ b/worker/task.go @@ -687,6 +687,15 @@ 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). + if srcFn.n != len(q.UidList.Uids) { + 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) From 3ca24c98040ac2058122bc21c7fbb909e95c3b4c Mon Sep 17 00:00:00 2001 From: harshil Date: Thu, 1 Oct 2020 13:11:15 +0530 Subject: [PATCH 2/2] fixed some stuff --- worker/task.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worker/task.go b/worker/task.go index 0bc71a4c05e..12326cffdf6 100644 --- a/worker/task.go +++ b/worker/task.go @@ -691,9 +691,12 @@ func (qs *queryState) handleUidPostings( // 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). - if srcFn.n != len(q.UidList.Uids) { - 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) + 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.