mfbx9da4 / deep-email-validator

Validates regex, typos, disposable, dns and smtp
MIT License
873 stars 92 forks source link

RangeError: Maximum call stack size exceeded #3

Closed iAlex97 closed 4 years ago

iAlex97 commented 4 years ago

Hello, first of all I'd like to thank you for such a cool library. I've been trying to use it for some project of mine and it worked really well most of the time, except for some invalid addresses which caused this issue:

Exception in PromiseRejectCallback:
internal/process/promises.js:94
function resolveError(type, promise, reason) {
                     ^

RangeError: Maximum call stack size exceeded
internal/errors.js:309
  err.stack;
      ^

RangeError: Maximum call stack size exceeded
    at addCodeToName (internal/errors.js:309:7)
    at new NodeError (internal/errors.js:270:7)
    at doWrite (_stream_writable.js:399:19)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Socket.<anonymous> (/home/ialex/Projects/Node/deep-email-validator/dist/smtp/smtp.js:40:20)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:482:12)
    at Socket.<anonymous> (/home/ialex/Projects/Node/deep-email-validator/dist/smtp/smtp.js:31:20)
    at Socket.emit (events.js:315:20)

Upon further investigation, the issue occurred when the fail event of the socket was triggered by writing to an already closed socket. This caused the event to be triggered again due to this exception, all while trying to resolve the promise (possibly due to the error event being triggered by writing to a closed socket?).

Anyhow, I've opened PR #2 which adds some checks before writing to the socket and it seems the error goes away while returning an invalid address status:

{
  valid: false,
  validators: {
    regex: { valid: true },
    typo: { valid: true },
    disposable: { valid: true },
    mx: { valid: true },
    smtp: { valid: false, reason: 'Unrecognized SMTP response.' }
  },
  reason: 'smtp'
}
Bug-Reaper commented 4 years ago

Also wanted to say thanks for this cool library. Hope this PR get's merged sometime soon. Does this error occur often in production? @iAlex97

mfbx9da4 commented 4 years ago

Hey I'm really sorry I didn't see this until now! Merging your PR!