TypeError: undefined is not a function, at storeHeader (_http_outgoing.js)

138 views
Skip to first unread message

Frederic Brodbeck

unread,
May 27, 2015, 7:52:16 AM5/27/15
to nod...@googlegroups.com
hi,

I wrote a program that – usually after several hours – crashes with this error:

```
TypeError: undefined is not a function
    at storeHeader (_http_outgoing.js:303:19)
    at ClientRequest.OutgoingMessage._storeHeader (_http_outgoing.js:229:9)
    at ClientRequest._implicitHeader (_http_client.js:187:8)
    at ClientRequest.OutgoingMessage.end (_http_outgoing.js:529:10)
    at Request.end (/Volumes/Macintosh HD 2/Projects/projects/xyz/node_modules/request/request.js:1533:12)
    at end (/Volumes/Macintosh HD 2/Projects/projects/xyz/node_modules/request/request.js:734:14)
    at Immediate._onImmediate (/Volumes/Macintosh HD 2/Projects/projects/xyz/node_modules/request/request.js:748:7)
    at processImmediate [as _immediateCallback] (timers.js:358:17)
```

it uses the `request` module for making http requests, and it does them periodically. — I'm not sure if it's a request or a node.js problem though.

multiple intervals are set, and I assume it happens in one of them, but the stack trace doesn't tell me which one. is there any way to find out?

node v0.12.4.
os x 10.10.3

thanks in advance

Jimb Esser

unread,
May 28, 2015, 8:44:46 PM5/28/15
to nod...@googlegroups.com
Looking at the code that is crashing [1], it looks like a header has a non-string value (it's trying to call String's "replace" method on a header value).  Arguably, this is a bug in the Node code (it's implicitly converting the value to a string on the previous and following lines, but not on the line that's crashing).  Additionally, the non-string value, when converted to a string, has newlines in it.

If you're setting any custom headers, check to see if they're strings or something else (an Error object is a very likely culprit that would get automatically converted to a string with newlines in it).  If you can reproduce this in a simple case, maybe also file a bug with Node, since, from glancing through the code, it seems that Node will accept non-string header values and happily convert them to strings, unless the converted string has a newline in it, which is oddly inconsistent.

Hope this helps!

Frederic Brodbeck

unread,
Jun 2, 2015, 9:46:08 AM6/2/15
to nod...@googlegroups.com
I was using a module to generate user agent strings and and used those in the header; looks like the problem was that that module didn't work reliably.
thanks a lot jimb!
Reply all
Reply to author
Forward
0 new messages