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 set property 'hostname' of undefined #3514

Closed
JetLua opened this issue Jun 6, 2017 · 22 comments
Closed

TypeError: Cannot set property 'hostname' of undefined #3514

JetLua opened this issue Jun 6, 2017 · 22 comments
Assignees
Labels
Milestone

Comments

@JetLua
Copy link

@JetLua JetLua commented Jun 6, 2017

/mnt/npm/lib/node_modules/hapi/lib/request.js:229
        this.info.hostname = url.hostname;
                           ^

TypeError: Cannot set property 'hostname' of undefined
    at internals.Request._setUrl (/mnt/npm/lib/node_modules/hapi/lib/request.js:229:28)
    at new internals.Request (/mnt/npm/lib/node_modules/hapi/lib/request.js:83:10)
    at module.exports.internals.Generator.internals.Generator.request (/mnt/npm/lib/node_modules/hapi/lib/request.js:31:21)
    at Server.<anonymous> (/mnt/npm/lib/node_modules/hapi/lib/connection.js:260:48)
    at emitTwo (events.js:125:13)
    at Server.emit (events.js:213:7)
    at parserOnIncoming (_http_server.js:601:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
  • node version: 8.0.0
  • hapi version: 16.4.1
  • os: debian 8
@Marsup
Copy link
Contributor

@Marsup Marsup commented Jun 6, 2017

How about a way to reproduce this ?

@JetLua
Copy link
Author

@JetLua JetLua commented Jun 6, 2017

I am also looking for how to reproduce. It always runs normally for a while, and then this error occurs.

@AJamesPhillips
Copy link
Contributor

@AJamesPhillips AJamesPhillips commented Jun 7, 2017

@JetLua it might be a binding issue, what is the value of this when it fails. Perhaps put it in a try catch and log the value of this. You might find its' the node global value.

@JetLua
Copy link
Author

@JetLua JetLua commented Jun 7, 2017

@AJamesPhillips Thanks.

I added a piece of code.

lib/request.js
2017-06-07_214946

Currently running normally, no output.

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 7, 2017

I'm getting the same error with latest hapi
happens around every 30min, I also added a log to check what is going on
will report back when I got something

@AdriVanHoudt AdriVanHoudt self-assigned this Jun 7, 2017
@AJamesPhillips
Copy link
Contributor

@AJamesPhillips AJamesPhillips commented Jun 7, 2017

Just curious (no obligation to answer):

  • how many connections are you running @AdriVanHoudt and @JetLua ?
  • what plugins are you using? (and have you changed any of their versions or is it only hapi you changed?)
  • what version of hapi was it ok on?
  • I assume the this.info error is occurring in a route request handler?

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 7, 2017

Still looking but has probably to do with calling https://github.com/hapijs/hapi/blob/master/lib/request.js#L83
before https://github.com/hapijs/hapi/blob/master/lib/request.js#L147

working on a reproducible case :P

@arb
Copy link
Contributor

@arb arb commented Jun 7, 2017

How are you starting your server and registering plugins?

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 7, 2017

Not different from hapi 16.2 :P
I think this is something that just came up since hapi never accessed this.info inside Request like that before and every case I've tried so far worked correctly. I will add some more logging and wait for that to get a reproducible case

@JetLua
Copy link
Author

@JetLua JetLua commented Jun 8, 2017

@AJamesPhillips @AdriVanHoudt

With the output:

{ _eventListeners: 
   { finish: { handlers: null, flags: [Object] },
     peek: { handlers: null, flags: [Object] },
     disconnect: { handlers: null, flags: [Object] } },
  _notificationsQueue: [],
  _eventsProcessing: false,
  _sourcePodiums: [],
  _bench: { ts: 9712062273.021809 },
  connection: 
   { _eventListeners: 
      { route: [Object],
        'request-internal': [Object],
        request: [Object],
        'request-error': [Object],
        response: [Object],
        tail: [Object] },
     _notificationsQueue: [],
     _eventsProcessing: false,
     _sourcePodiums: [ [Object], [Object] ],
     settings: 
      { compression: true,
        router: [Object],
        routes: [Object],
        port: 8000,
        labels: [],
        autoListen: true },
     server: 
      { _settings: [Object],
        _caches: [Object],
        _handlers: {},
        _methods: [Object],
        _events: [Object],
        _dependencies: [],
        _registrations: {},
        _heavy: [Object],
        _mime: [Object],
        _replier: [Object],
        _requestor: [Object],
        _decorations: {},
        decorations: [Object],
        _plugins: {},
        _app: {},
        _registring: false,
        _state: 'started',
        _extensionsSeq: 0,
        _extensions: [Object],
        _eventListeners: [Object],
        _notificationsQueue: [],
        _eventsProcessing: false,
        _sourcePodiums: [],
        _parent: null,
        root: [Circular],
        app: {},
        connections: [Array],
        load: [Object],
        methods: {},
        mime: [Object],
        plugins: {},
        settings: [Object],
        version: '16.4.1',
        realm: [Object],
        auth: [Object],
        cache: [Object],
        info: [Object],
        listener: [Object],
        registrations: {} },
     type: 'tcp',
     _started: true,
     _connections: { '80.82.78.38:36636': [Object] },
     _onConnection: [Function],
     registrations: {},
     _extensions: 
      { onRequest: [Object],
        onPreAuth: [Object],
        onPostAuth: [Object],
        onPreHandler: [Object],
        onPostHandler: [Object],
        onPreResponse: [Object] },
     _requestCounter: { value: 10150, min: 10000, max: 99999 },
     _load: { _process: [Object], settings: [Object] },
     _compression: { encodings: [Array], _encoders: [Object], _decoders: [Object] },
     states: { settings: [Object], cookies: {}, names: [] },
     auth: 
      { connection: [Circular],
        _schemes: {},
        _strategies: {},
        settings: [Object],
        api: {} },
     _router: 
      { settings: [Object],
        routes: [Object],
        ids: {},
        vhosts: null,
        specials: [Object] },
     plugins: {},
     app: {},
     listener: 
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 1,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        keepAliveTimeout: 5000,
        _pendingResponseData: 0,
        maxHeadersCount: null,
        _connectionKey: '4:0.0.0.0:8000',
        [Symbol(asyncId)]: 17 },
     info: 
      { created: 1496807385231,
        started: 1496807385264,
        host: 'iZ23hugf5kzZ',
        port: 8000,
        protocol: 'http',
        id: 'iZ23hugf5kzZ:15365:j3mggy33',
        uri: 'http://iZ23hugf5kzZ:8000',
        address: '0.0.0.0' } },
  server: 
   { _settings: 
      { debug: [Object],
        load: [Object],
        mime: null,
        useDomains: true,
        connections: [Object] },
     _caches: { _default: [Object] },
     _handlers: {},
     _methods: { server: [Circular], methods: {}, _normalized: {} },
     _events: 
      { _eventListeners: [Object],
        _notificationsQueue: [],
        _eventsProcessing: false,
        _sourcePodiums: [Array] },
     _dependencies: [],
     _registrations: {},
     _heavy: 
      { settings: [Object],
        _eventLoopTimer: null,
        _loadBench: [Object],
        load: [Object] },
     _mime: Mimos { _byType: [Object], _byExtension: [Object] },
     _replier: { _decorations: null },
     _requestor: { _decorations: null },
     _decorations: {},
     decorations: { request: [], reply: [], server: [] },
     _plugins: {},
     _app: {},
     _registring: false,
     _state: 'started',
     _extensionsSeq: 0,
     _extensions: 
      { onPreStart: [Object],
        onPostStart: [Object],
        onPreStop: [Object],
        onPostStop: [Object] },
     _eventListeners: 
      { route: [Object],
        'request-internal': [Object],
        request: [Object],
        'request-error': [Object],
        response: [Object],
        tail: [Object],
        log: [Object],
        start: [Object],
        stop: [Object] },
     _notificationsQueue: [],
     _eventsProcessing: false,
     _sourcePodiums: [],
     _parent: null,
     root: [Circular],
     app: {},
     connections: [ [Object] ],
     load: { eventLoopDelay: 0, heapUsed: 0, rss: 0 },
     methods: {},
     mime: Mimos { _byType: [Object], _byExtension: [Object] },
     plugins: {},
     settings: 
      { debug: [Object],
        load: [Object],
        mime: null,
        useDomains: true,
        connections: [Object] },
     version: '16.4.1',
     realm: 
      { _extensions: [Object],
        modifiers: [Object],
        plugin: '',
        pluginOptions: {},
        plugins: {},
        settings: [Object] },
     auth: 
      { default: [Function: default],
        scheme: [Function: scheme],
        strategy: [Function: strategy],
        test: [Function: test],
        api: {} },
     cache: { [Function: policy] provision: [Function] },
     info: 
      { created: 1496807385231,
        started: 1496807385264,
        host: 'iZ23hugf5kzZ',
        port: 8000,
        protocol: 'http',
        id: 'iZ23hugf5kzZ:15365:j3mggy33',
        uri: 'http://iZ23hugf5kzZ:8000',
        address: '0.0.0.0' },
     listener: 
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 1,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        keepAliveTimeout: 5000,
        _pendingResponseData: 0,
        maxHeadersCount: null,
        _connectionKey: '4:0.0.0.0:8000',
        [Symbol(asyncId)]: 17 },
     registrations: {} },
  url: 
   Url {
     protocol: 'http:',
     slashes: true,
     auth: null,
     host: 'www.baidu.com',
     port: null,
     hostname: 'www.baidu.com',
     hash: null,
     search: '',
     query: {},
     pathname: '/cache/global/img/gs.gif',
     path: '/cache/global/img/gs.gif',
     href: 'http://www.baidu.com/cache/global/img/gs.gif' },
  query: {},
  path: '/cache/global/img/gs.gif',
  method: null,
  mime: null,
  setUrl: [Function],
  setMethod: [Function] }

@JetLua
Copy link
Author

@JetLua JetLua commented Jun 8, 2017

In the output above,
I'm a little confused:

this.url.host: 'www.baidu.com'
this.server.info.host: 'iZ23hugf5kzZ'
this.connection.info.host: 'iZ23hugf5kzZ'
//without: this.info

Start the script:

const
    hapi = require('hapi'),
    ssr = require('./lib/ssr'),
    api = require('./lib/api'),
    app = new hapi.Server()

app.connection({port: 8000})

ssr(app)
api(app)

app.start()

@AJamesPhillips
Copy link
Contributor

@AJamesPhillips AJamesPhillips commented Jun 8, 2017

@JetLua more context please. Those with more experience of hapi might be able to solve it from what you've posted but the following would be very useful to know:

  1. The output you posted (2 above comments) is the result of running the scripts (above) and so is the what you saw from the console.log(this) line?
  2. What are the scripts you're running in ./lib/ssr and ./lib/api, you'll need to reduce them down to something all in one file and not more than a hundred lines. Please see: http://sscce.org/

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 8, 2017

I got some more info and tried all the test cases but could not reproduce

{
	"__error_callsites": [{}, {}, {}, {}, {}, {}, {}, {}, {}],
	"url": {
		"href": "http://www.baidu.com/",
		"path": "/",
		"pathname": "/",
		"query": {},
		"search": "",
		"hash": null,
		"hostname": "www.baidu.com",
		"port": null,
		"host": "www.baidu.com",
		"auth": null,
		"slashes": true,
		"protocol": "http:"
	},
	"orig": "HTTP://www.baidu.com/",
	"message": "this.info not set while trying to set hostname to www.baidu.com",
	"stack": "Error: this.info not set while trying to set hostname to www.baidu.com\n    at internals.Request.internals.Request._setUrl (/home/adri/Server/node_modules/hapi/lib/request.js:230:12)\n    at new internals.Request.options (/home/adri/Server/node_modules/hapi/lib/request.js:83:10)\n    at internals.Generator.request (/home/adri/Server/node_modules/hapi/lib/request.js:31:21)\n    at Server.<anonymous> (/home/adri/Server/node_modules/hapi/lib/connection.js:260:48)\n    at emitTwo (events.js:87:13)\n    at Server.emit (events.js:172:7)\n    at Server.emit (/home/adri/Server/node_modules/opbeat/lib/instrumentation/http-shared.js:54:19)\n    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:539:12)\n    at HTTPParser.parserOnHeadersComplete (_http_common.js:97:23)"
}

Weirdly it also shows baidu :D
url is the new url object trying to be set and orig is what is given to _setUrl before anything happens

@joshferrell
Copy link

@joshferrell joshferrell commented Jun 9, 2017

Is there any temporary work around that anyone has found? I'm having the same issue. Hard to tell if rolling back a version with Hapi actually fixed it since sometimes it runs for 10 hours and crashes, others 15 minutes.

Node: v7.10.0
Hapi: 16.3.0
OS: Docker Native

@AJamesPhillips
Copy link
Contributor

@AJamesPhillips AJamesPhillips commented Jun 9, 2017

@joshferrell you got any logs? Seen anything from baidu.com (both @AdriVanHoudt and @JetLua have)? It sounds like it might be due to a badly formed request coming in and hapi is now breaking on it? @AdriVanHoudt

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 9, 2017

@joshferrell going a version or 2 back should solve it, on the other hand it should not break your server per se since this is caused by some weird requests that you probably didn't handle anyway :P
I can do a PR to fix it but reproducing seems close to impossible (for me at least)

@mtharrison
Copy link
Contributor

@mtharrison mtharrison commented Jun 9, 2017

So two of you with different apps are getting errors on requests to baidu.com? Was I reading that right? Does your app have anything to do with baidu.com? Can you share your code?

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 9, 2017

Nothing to do with it, I would assume a crawler or massive coincidence.

And I pointed out what is very likely to be the cause code wise ☝️ but I can't reproduce it and I can't share my whole server :P

I currently have no time to make a something to catch it properly in production.
If you have debug suggestion for stuff to log I can easily do that and share the results

@Senseye
Copy link

@Senseye Senseye commented Jun 9, 2017

I'm also experiencing this issue.
Same logs as in description.

npm info it worked if it ends with ok
npm info using npm@2.15.11
npm info using node@v4.6.2
npm info preapp-dev mt-client-app-server@0.0.1
npm info app-dev mt-client-app-server@0.0.1

> mt-client-app-server@0.0.1 app-dev /usr/src/app
> NODE_ENV=development node server.js

Server running at: http://374a6f483b5e:9000 | development
Debug: internal, implementation, error
    TypeError: Uncaught error: Cannot read property 'result' of undefined
    at Request._callback (/usr/src/app/server.js:119:60)
    at Request.self.callback (/usr/src/app/node_modules/request/request.js:188:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/usr/src/app/node_modules/request/request.js:1171:10)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/usr/src/app/node_modules/request/request.js:1091:12)
    at IncomingMessage.g (events.js:260:16)
    at emitNone (events.js:72:20)
Debug: internal, implementation, error
    TypeError: Uncaught error: Cannot read property 'result' of undefined
    at Request._callback (/usr/src/app/server.js:119:60)
    at Request.self.callback (/usr/src/app/node_modules/request/request.js:188:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/usr/src/app/node_modules/request/request.js:1171:10)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/usr/src/app/node_modules/request/request.js:1091:12)
    at IncomingMessage.g (events.js:260:16)
    at emitNone (events.js:72:20)
/usr/src/app/node_modules/hapi/lib/request.js:229
        this.info.hostname = url.hostname;
                           ^

TypeError: Cannot set property 'hostname' of undefined
    at internals.Request.internals.Request._setUrl (/usr/src/app/node_modules/hapi/lib/request.js:229:28)
    at new internals.Request.options (/usr/src/app/node_modules/hapi/lib/request.js:83:10)
    at internals.Generator.request (/usr/src/app/node_modules/hapi/lib/request.js:31:21)
    at Server.<anonymous> (/usr/src/app/node_modules/hapi/lib/connection.js:260:48)
    at emitTwo (events.js:87:13)
    at Server.emit (events.js:172:7)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:536:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)

npm info mt-client-app-server@0.0.1 Failed to exec app-dev script
npm ERR! Linux 4.4.0-62-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "app-dev"
npm ERR! node v4.6.2
npm ERR! npm  v2.15.11
npm ERR! code ELIFECYCLE
npm ERR! mt-client-app-server@0.0.1 app-dev: `NODE_ENV=development node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mt-client-app-server@0.0.1 app-dev script 'NODE_ENV=development node server.js'.
npm ERR! This is most likely a problem with the mt-client-app-server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     NODE_ENV=development node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs mt-client-app-server
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls mt-client-app-server
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log
root@vps277561:~#```

@sirgallifrey
Copy link
Contributor

@sirgallifrey sirgallifrey commented Jun 9, 2017

Is there any chance for any of you to log the raw request for one of those baidu calls?

@hueniverse hueniverse assigned hueniverse and unassigned AdriVanHoudt Jun 9, 2017
@hueniverse hueniverse added this to the 16.4.3 milestone Jun 9, 2017
@hueniverse hueniverse closed this in b8efbd9 Jun 9, 2017
@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Jun 9, 2017

This was identified by @mtharrison.

@AdriVanHoudt
Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Jun 9, 2017

@hueniverse thanks for the quick response 👌

GulajavaMinistudio added a commit to GulajavaMinistudio/hapi that referenced this issue Jun 10, 2017
Fix uninitialized request.info. Closes hapijs#3514
@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants