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

TypeError: Cannot read property 'accept-encoding' of undefined #39

Closed
baobeimm opened this issue Aug 14, 2013 · 20 comments
Closed

TypeError: Cannot read property 'accept-encoding' of undefined #39

baobeimm opened this issue Aug 14, 2013 · 20 comments

Comments

@baobeimm
Copy link

We are getting this error occasionally. any idea?

07/14/2013 21:58:003.856 [ERROR] [1289] TypeError: Cannot read property 'accept-encoding' of undefined
    at IncomingMessage.req.get.req.header (/home/ec2-user/stratus/node_modules/express/lib/request.js:54:26)
    at IncomingMessage.acceptedEncodings (/home/ec2-user/stratus/node_modules/express/lib/request.js:186:21)
    at Object.stringify (native)
    at Logger.Logger._emit [as _emit] (/home/ec2-user/stratus/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:685:16)
    at Logger.warn (/home/ec2-user/stratus/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:731:10)
    at Agent.Agent.mergeMetrics [as mergeMetrics] (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:351:21)
    at CollectorConnection.EventEmitter.emit [as emit] (events.js:99:17)
    at CollectorConnection.CollectorConnection.createDataSender (/home/ec2-user/stratus/node_modules/newrelic/lib/collector/connection.js:210:12)
---------------------------------------------
    at Agent.Agent.setupConnection [as setupConnection] (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:181:19)
    at Agent.Agent.start [as start] (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:103:8)
    at Object.<anonymous> (/home/ec2-user/stratus/node_modules/newrelic/index.js:42:11)
    at Module.Module._compile [as _compile] (module.js:449:26)
    at Object.Module._extensions..js [as .js] (module.js:467:10)
    at Module.Module.load [as load] (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.Module.require [as require] (module.js:362:17)
@othiym23
Copy link
Contributor

I think I have a fix for this in the version I'm about to push out (before the end of the next week!). Leave this bug open, and I'll post here when I've published the new version and we can see if I fixed it. Out of curiosity, is there anything in newrelic_agent.log about failures in connecting to the collector?

@baobeimm
Copy link
Author

Yes there was an error about failed connection

@othiym23
Copy link
Contributor

Fixed in b13179b. Thanks for the report!

@baobeimm
Copy link
Author

Upgraded to 0.10.1, still hit this issue, after

{"name":"newrelic","hostname":"ip-10-176-145-152","pid":1746,"component":"data_sender","level":50,"msg":"Got 503 as a response code from the collector.","time":"2013-08-23T21:46:30.643Z","v":0}
Cannot read property 'accept-encoding' of undefined
    at req.get.req.header (/home/ec2-user/stratus/node_modules/express/lib/request.js:54:26)
    at IncomingMessage.acceptedEncodings (/home/ec2-user/stratus/node_modules/express/lib/request.js:186:21)
    at Object.stringify (native)
    at Logger._emit (/home/ec2-user/stratus/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:685:16)
    at Logger.warn (/home/ec2-user/stratus/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:731:10)
    at Agent.mergeMetrics (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:359:10)
    at EventEmitter.emit (events.js:99:17)
    at CollectorConnection.createDataSender (/home/ec2-user/stratus/node_modules/newrelic/lib/collector/connection.js:214:10)
---------------------------------------------
    at Agent.setupConnection (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:187:19)
    at Agent.start (/home/ec2-user/stratus/node_modules/newrelic/lib/agent.js:109:8)
    at Object.<anonymous> (/home/ec2-user/stratus/node_modules/newrelic/index.js:42:11)
    at Module._compile (module.js:449:26)
    at Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Module._load (module.js:312:12)
    at Module.require (module.js:362:17)^[[39m

@othiym23
Copy link
Contributor

This looks like a bug in the agent, but I'm going to need some help from you to figure out what's going on, because the request shouldn't be in scope with the logger like that. Can you send

  1. package.json
  2. the top of the file where you're requiring the New Relic module, at least up to, and 5 lines after, the line saying require('newrelic') itself
  3. a gzipped version of newrelic_agent.log

to forrest@newrelic.com? Thanks!

@othiym23 othiym23 reopened this Aug 24, 2013
@othiym23
Copy link
Contributor

othiym23 commented Oct 3, 2013

Closing this, as this ticket is a month old and a huge chunk of stuff related to this issue has changed in the interim. Reopen if you run into it again.

@othiym23 othiym23 closed this as completed Oct 3, 2013
@len-am
Copy link

len-am commented Feb 13, 2014

Hi, can you reopen this issue. We're getting a very error but different trace on 1.3.1:

TypeError: Cannot read property 'accept-encoding' of undefined
    at req.get.req.header (/opt/appcelerator/360/node_modules/express/lib/request.js:54:26)
    at IncomingMessage.acceptedEncodings (/opt/appcelerator/360/node_modules/express/lib/request.js:186:21)
    at Object.stringify (native)
    at Logger._emit (/opt/appcelerator/360/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:685:16)
    at Logger.trace (/opt/appcelerator/360/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:731:10)
    at ErrorTracer.add (/opt/appcelerator/360/node_modules/newrelic/lib/error.js:154:12)
    at _patchErrorTracerOntoCLS.callbacks.error (/opt/appcelerator/360/node_modules/newrelic/lib/transaction/tracer.js:40:20)
    at asyncCatcher (/opt/appcelerator/360/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:113:50)
    at _asyncFatalException (/opt/appcelerator/360/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:199:14)

When we ran into this issue, this caused our node app to crash during startup, so it continually crashes.

@len-am
Copy link

len-am commented Feb 13, 2014

@othiym23 some additional info. A crash in the useragent module was the underlying problem. Once I resolved the issue with useragent, I no longer got the newrelic crash. Nevertheless, the newrelic crash should not have occurred since we do want to report that the useragent crash occurred.

@othiym23
Copy link
Contributor

This is a tough bug to fix completely, because the crash is happening because of bad assumptions inside bunyan (that JSON.stringify will always succeed) and Express (that it's safe to put accessors on the request, and that the code in the accessors doesn't need guards). We can address it by being a little more careful about how we log errors, but the issue is not entirely in code over which we have control.

A repro case would be very helpful!

@othiym23 othiym23 reopened this Feb 13, 2014
@rcoup
Copy link

rcoup commented Feb 27, 2014

We're seeing this something very similar after upgrading from 1.2.0 to 1.3.2:

TypeError: Cannot read property 'accept' of undefined
    at IncomingMessage.<anonymous> (/path/to/app/191/node_modules/express/lib/request.js:54:26)
    at IncomingMessage.accepted (/path/to/app/191/node_modules/express/lib/request.js:182:21)
    at Object.stringify (native)
    at Logger._emit (/path/to/app/191/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:685:16)
    at Logger.error (/path/to/app/191/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:731:10)
    at /path/to/app/191/node_modules/newrelic/index.js:59:14
    at /path/to/app/191/node_modules/newrelic/lib/agent.js:151:14
    at retry (/path/to/app/191/node_modules/newrelic/lib/collector/api.js:87:14)
    at /path/to/app/191/node_modules/newrelic/lib/collector/api.js:117:23
    at /path/to/app/191/node_modules/newrelic/lib/collector/parse-response.js:115:36
    at /path/to/app/191/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:177:31
    at process._tickCallback (node.js:415:13)
27 Feb 03:32:49 - uncaughtException: 7b9e51cee61b4dacaac196b163556003$b58abd2d3a173bdaa8f7f7b4cdb0f1b6
quitting: { [TypeError: Cannot read property 'accept' of undefined]
  structuredStackTrace:
   [ { receiver: [Object], fun: [Function], pos: 1090 },
     { receiver: [Object], fun: [Function], pos: 4176 },
     { receiver: {}, fun: [Function: stringify], pos: 5703 },
     { receiver: [Object], fun: [Function], pos: 19300 },
     { receiver: [Object], fun: [Function], pos: 20911 },
     { receiver: undefined, fun: [Function], pos: 2195 },
     { receiver: undefined, fun: [Function], pos: 4933 },
     { receiver: undefined, fun: [Function: retry], pos: 2651 },
     { receiver: undefined, fun: [Function], pos: 3360 },
     { receiver: [Object], fun: [Function], pos: 4086 },
     { receiver: [Object], fun: [Function], pos: 5532 },
     { receiver: [Object],
       fun: [Function: _tickCallback],
       pos: 14030 } ] }
undefined

It's possible the app is exiting anyway and this error happens during cleanup, still digging into it.

@Janpot
Copy link

Janpot commented Apr 17, 2014

In my case https://github.com/mattinsler/longjohn was causing this issue. As soon as I removed it my app started working agin.

@devinfoley
Copy link

I'm seeing this issue in 1.5.2 (and earlier).

@bernieperez
Copy link

Has this been fixed? I just started noticing this as well. We are running a Docker container on OpsWorks.

App 907 stderr: TypeError: Cannot read property 'accept-encoding' of undefined
App 907 stderr:     at req.get.req.header (/path/to/app/node_modules/express/lib/request.js:55:26)
App 907 stderr:     at IncomingMessage.acceptedEncodings (/path/to/app/node_modules/express/lib/request.js:190:21)
App 907 stderr:     at Object.stringify (native)
App 907 stderr:     at Logger._emit (/path/to/app/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:685:16)
App 907 stderr:     at Logger.trace (/path/to/app/node_modules/newrelic/node_modules/bunyan/lib/bunyan.js:731:10)
App 907 stderr:     at ErrorTracer.add (/path/to/app/node_modules/newrelic/lib/error.js:195:12)
App 907 stderr:     at error (/path/to/app/node_modules/newrelic/lib/transaction/tracer.js:40:20)
App 907 stderr:     at asyncCatcher (/path/to/app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:113:50)
App 907 stderr:     at _asyncFatalException (/path/to/app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:199:14)
[ 2014-06-13 18:52:43.0205 111/7f8a5f887700 Pool2/Pool.h:777 ]: Process (pid=907, group=/home/app/webapp#default) no longer exists! Detaching it from the pool.
App 933 stdout: 

Thanks

@bernieperez
Copy link

After I commented out require('newrelic'); it started working :( I think there might have been a regression.

@txase
Copy link

txase commented Jun 13, 2014

@bernieperez @devinfoley Are you able to provide a repro case? Bugs for which we have repro cases get bumped in priority as we can fix them much faster. If you can't provide a repro case, we will still try to fix it, it just may take longer.

Thanks!

@bernieperez
Copy link

What information do you need for a repo case?

@txase
Copy link

txase commented Jun 13, 2014

@bernieperez The most useful is if you can put up a github repo with an example app the exhibits the behavior you see. If you see the behavior in your own app, but don't want to make it publicly visible, try making a tiny example app with just enough functionality to show the issue.

Thanks!

@bernieperez
Copy link

Got it, we are in the middle of a workout right now, but as an FYI we are using Docker with Phusion-Passenger to run our node app in production.
https://github.com/phusion/passenger/wiki/Phusion-Passenger%3A-Node.js-tutorial#how_does_it_work

@bernieperez
Copy link

We got it working again. Notice this in the error logs:
Error: EACCES, open '/home/app/webapp/newrelic_agent.log'

Manually created a file newrelic_agent.log and chmod to 777 and it worked. I guess it was crashing when it couldn't create the agent file.

Our real fix was to update the config:

logging : {
    /**
     * Where to put the log file -- by default just uses process.cwd +
     * 'newrelic_agent.log'. A special case is a filepath of 'stdout',
     * in which case all logging will go to stdout, or 'stderr', in which
     * case all logging will go to stderr.
     *
     * @env NEW_RELIC_LOG
     */
    filepath : require('path').join(process.cwd(), 'newrelic_agent.log')
  },

with a valid file path.

@txase
Copy link

txase commented Jun 26, 2014

Hi everyone,

This issue has multiple people reporting in their individual issues, and although they may look related, there is a good chance they are independent problems. Some may also have been resolved by now.

I am going to close this issue, but I encourage anyone who still is having problems after updating to the latest version of the Node.js agent to open a new issue.

Thanks for your understanding as we tidy up our issue tracker!

@txase txase closed this as completed Jun 26, 2014
cmcadams-newrelic pushed a commit to cmcadams-newrelic/node-newrelic that referenced this issue Jan 29, 2024
NEWRELIC-5570 added sample app with injector of traffic
jsumners-nr pushed a commit to jsumners-nr/node-newrelic that referenced this issue Apr 11, 2024
bizob2828 pushed a commit that referenced this issue Jul 31, 2024
changed repolinter workflow to check for community plus rules
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

8 participants