Kibana: HapiJS req.connection.inject() broken via the onRequest handler in setup_connection.js

Created on 1 Dec 2016  路  5Comments  路  Source: elastic/kibana

Kibana version:5.0.1

Elasticsearch version:5.0.1

Server OS version: Dev Environment, Redhat7

Browser version: Chrome 54 (64-bit)

Browser OS version: Chrome 54 (64-bit)

Original install method (e.g. download page, yum, from source, etc.): Source checkout

Description of the problem including expected versus actual behavior:

When trying to use the request.connection.iject (or server.inject) hapiJS functions to call another route from a Kibana plugin, the inject fails with the stacktrace given below, instead of successfully invoking the specified route. This appears to be because of a subtlety in how inject() works that the onRequest handler isn't expecting. The expected behaviour would be that the route is successfully invoked.

Steps to reproduce:

  1. Create a plugin (e.g. through the plugin generator) with the following init funtion
    init(server, options) {

      server.route({
        path: '/my-plugin/route1',
        method: 'GET',
        handler(req, reply) {
          reply ('HELLO ');
        }
      });

      server.route({
        path: '/my-plugin/route2',
        method: 'GET',
        handler(req, reply) {
          req.connection.inject('/my-plugin/route1', function (origResp) {
            reply (origResp.payload + 'World!');
          });
        }
      });
    },
  1. Use npm start if using the plugin-helpers module, or start kibana with the pluginPath specified appropriately
  2. Call https://localhost:5601/:basepath/my-plugin/route1 and note that Hello is successfully returned

    1. Call https://localhost:5601/:basepath/my-plugin/route2 and note that you get a 500 error returned, and that the console contains the below stacktrace

Errors in browser console (if relevant): N/A

Provide logs and/or server output (if relevant):

server   error  [14:14:40.207]  TypeError: Uncaught error: Cannot read property 'encrypted' of undefined
    at /home/megan/analytics/kibana-plugins/kibana/src/server/http/setup_connection.js:51:27
    at Items.serial (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:403:22)
    at iterate (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at Object.exports.serial (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/node_modules/items/lib/index.js:39:9)
    at _protect.run (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:398:15)
    at internals.Protect.run (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/protect.js:64:5)
    at internals.Request._invoke (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:396:19)
    at internals.Request._execute (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/request.js:305:10)
    at Domain.request._protect.enter (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:261:25)
    at Domain.run (domain.js:221:14)
    at internals.Protect.enter (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/protect.js:80:17)
    at /home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:259:30
    at req.prepare (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/index.js:55:30)
    at internals.Request.prepare (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/request.js:96:16)
    at Object.exports.inject (/home/megan/analytics/kibana-plugins/kibana/node_modules/shot/lib/index.js:55:16)
    at internals.Connection.inject (/home/megan/analytics/kibana-plugins/kibana/node_modules/hapi/lib/connection.js:303:10)

This is preventing me from invoking multiple routes with my plugin to process the output as appropriate.

bug

All 5 comments

I _think_ this could be handled by a defensive check in handleRequest where it will pass the request on if there isn't a socket associated with it, similar to how it does if it's already an https request. Though I haven't tested such a theory yet

I think that's correct @meganwalker-ibm. Mind submitting an PR?

Working on it, seems to work as expected. Though having trouble getting the npm run test to pass even before I've made my one line change. But that's for a separate discussion :)

See PR #9332 @spalger

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stacey-gammon picture stacey-gammon  路  3Comments

Ginja picture Ginja  路  3Comments

socialmineruser1 picture socialmineruser1  路  3Comments

ctindel picture ctindel  路  3Comments

cafuego picture cafuego  路  3Comments