Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash in sendgrid module due to parsing bad response #94

Closed
spollack opened this issue Sep 30, 2013 · 5 comments
Closed

crash in sendgrid module due to parsing bad response #94

spollack opened this issue Sep 30, 2013 · 5 comments

Comments

@spollack
Copy link

We had a production crash last night in the sendgrid module. At line 83 in sendgrid.js, there is a call JSON.parse(body);. This threw an exception because apparently the sendgrid service must have sent an unexpected response. calls to JSON.parse should always be wrapped in a try/catch to handle this sort of case.

Here was the stack at the crash:

undefined:1
<html>
^
SyntaxError: Unexpected token <
    at Object.parse (native)
    at Request._callback (/app/node_modules/sendgrid/lib/sendgrid.js:83:23)
    at Request.init.self.callback (/app/node_modules/sendgrid/node_modules/request/index.js:148:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.onResponse (/app/node_modules/sendgrid/node_modules/request/index.js:886:14)
    at Request.EventEmitter.emit (events.js:126:20)
    at IncomingMessage.Request.onResponse.buffer (/app/node_modules/sendgrid/node_modules/request/index.js:837:12)
    at IncomingMessage.Proxy.callback.args.(anonymous function) (/app/node_modules/nodetime/lib/core/proxy.js:131:20)
    at IncomingMessage.EventEmitter.emit (events.js:126:20)
    at IncomingMessage._emitEnd (http.js:366:10)
    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
    at CleartextStream.socketOnData [as ondata] (http.js:1485:20)
    at CleartextStream.CryptoStream._push (tls.js:544:27)
    at SecurePair.cycle (tls.js:898:20)
    at EncryptedStream.CryptoStream.write (tls.js:285:13)
    at Socket.ondata (stream.js:38:26)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:397:14) EXCEPT

@spollack
Copy link
Author

By the way, this needs to be fixed in the sendgrid module, as we have none of our own app code on the stack to catch this exception when it happens.

@motdotla
Copy link
Contributor

Thanks for catching this Seth. I just landed and will look and fix it as soon as possible. If you get to creating the pull request first then I'll review. Otherwise I'll code it up. 


Sent from Mailbox for iPhone

On Mon, Sep 30, 2013 at 2:01 PM, Seth Pollack notifications@github.com
wrote:

By the way, this needs to be fixed in the sendgrid module, as we have none of our own app code on the stack to catch this exception when it happens.

Reply to this email directly or view it on GitHub:
#94 (comment)

@spollack
Copy link
Author

Thanks. if you can make the fix that would be great.

I figured you'd want to look at it, for a couple of reasons:

  1. if there are other places in the codebase where JSON.parse is called
  2. to understand why your backend server sent this unexpected response.

@motdotla
Copy link
Contributor

motdotla commented Oct 1, 2013

@spollack this is fixed now in 0.3.1.

Latest should be up on npm within the next 15 minutes. https://npmjs.org/package/sendgrid

Fix here: https://github.com/sendgrid/sendgrid-nodejs/blob/master/lib/sendgrid.js

Internally, it looks like it was related to a temporary timeout issue we had.

@motdotla motdotla closed this as completed Oct 1, 2013
@spollack
Copy link
Author

spollack commented Oct 1, 2013

Thanks @scottmotte !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants