diff --git a/src/runtime/stack.go b/src/runtime/stack.go index b21c9c95182..6e0d157630b 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -1064,7 +1064,9 @@ func newstack() { // recheck the bounds on return.) if f := findfunc(gp.sched.pc); f.valid() { max := uintptr(funcMaxSPDelta(f)) - for newsize-gp.sched.sp < max+_StackGuard { + needed := max + _StackGuard + used := gp.stack.hi - gp.sched.sp + for newsize-used < needed { newsize *= 2 } }