async-validator icon indicating copy to clipboard operation
async-validator copied to clipboard

RangeError: Maximum call stack size exceeded (爆栈问题)

Open huyansheng3 opened this issue 6 years ago • 2 comments

image

image

http://2ality.com/2014/04/call-stack-size.html

v8 max call stack in chrome is 1W+ , our validate series length is 370 ,so the asyncSerialArray and func call stack is over 1W+, so the Maximum call stack size occur.

but the asyncSerialArray may be written with tail recursive.

function asyncSerialArray(arr, func, callback) {
  var index = 0
  var arrLength = arr.length

  return function next(errors) {
    if (errors && errors.length) {
      callback(errors)
      return
    }
    var original = index
    index = index + 1
    if (original < arrLength) {
      func(arr[original], next)
    } else {
      callback([])
    }
  }
}

maybe i can provide pr for this ?

huyansheng3 avatar Jun 03 '18 06:06 huyansheng3

put an setTimeout function can solve the problem. Maybe the library should consider this situation?

huyansheng3 avatar Jun 08 '18 10:06 huyansheng3

加个setTimeout果然解决了

jddk avatar Jan 07 '20 01:01 jddk