From 8551200f8b106d4f26d79898165122690d716ec0 Mon Sep 17 00:00:00 2001 From: Ashish Goswami Date: Wed, 17 Jun 2020 10:54:35 +0530 Subject: [PATCH] Avoid panic in handleValuePostings (#5652) Fixes: DGRAPH-1608 srcFn.n should be equal to len(q.UidList.Uids) for 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". We have tried to reproduce this but couldn't find any edge case which will result in this panic. So for now we are just logging when srcFn.n != len(q.UidList.Uids) and returning error when this happens. --- worker/task.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/worker/task.go b/worker/task.go index eda4d178da6..338ccc147d4 100644 --- a/worker/task.go +++ b/worker/task.go @@ -358,6 +358,15 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er 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 "+ + "handleValuePostings", srcFn.n, len(q.UidList.GetUids()), srcFn) + } + // This function has small boilerplate as handleUidPostings, around how the code gets // concurrently executed. I didn't see much value in trying to separate it out, because the core // logic constitutes most of the code volume here.