Skip to content

Commit cd8d0b9

Browse files
authored
fix(utils): splitCtx return original timeout when it is less than min timeout (#2228)
## Overview Handle case when timeout left in original context is less than min timeout. Also refactored one more if because it is nicer this way.
1 parent 301cdbe commit cd8d0b9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

share/getters/utils.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,16 @@ func ctxWithSplitTimeout(
115115
return context.WithTimeout(ctx, minTimeout)
116116
}
117117

118-
timeout := time.Until(deadline) / time.Duration(splitFactor)
119-
if minTimeout == 0 || timeout > minTimeout {
120-
return context.WithTimeout(ctx, timeout)
118+
timeout := time.Until(deadline)
119+
if timeout < minTimeout {
120+
return context.WithCancel(ctx)
121121
}
122-
return context.WithTimeout(ctx, minTimeout)
122+
123+
splitTimeout := timeout / time.Duration(splitFactor)
124+
if splitTimeout < minTimeout {
125+
return context.WithTimeout(ctx, minTimeout)
126+
}
127+
return context.WithTimeout(ctx, splitTimeout)
123128
}
124129

125130
// ErrorContains reports whether any error in err's tree matches any error in targets tree.

0 commit comments

Comments
 (0)