Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Middleware crashes with serverless-http #129

Closed
jguepin opened this issue Feb 9, 2018 · 2 comments
Closed

Middleware crashes with serverless-http #129

jguepin opened this issue Feb 9, 2018 · 2 comments

Comments

@jguepin
Copy link
Contributor

jguepin commented Feb 9, 2018

Expected behavior

The bugsnag middlewares should work with serverless-http that is a middleware wrapper for serverless use (AWS Lambda), compatible with express / connect middlewares.

Observed behavior

Every request returns an error:

TypeError: connection.address is not a function
    at requestInfo (/var/task/node_modules/bugsnag/lib/request_info.js:5:44)
    at Bugsnag.requestHandler (/var/task/node_modules/bugsnag/lib/bugsnag.js:205:25)
    at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/task/node_modules/express/lib/router/index.js:317:13)
    at /var/task/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/task/node_modules/express/lib/router/index.js:335:12)
    at next (/var/task/node_modules/express/lib/router/index.js:275:10)
    at expressInit (/var/task/node_modules/express/lib/middleware/init.js:40:5)
    at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/task/node_modules/express/lib/router/index.js:317:13)
    at /var/task/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/task/node_modules/express/lib/router/index.js:335:12)
    at next (/var/task/node_modules/express/lib/router/index.js:275:10)
    at query (/var/task/node_modules/express/lib/middleware/query.js:45:5)
    at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/task/node_modules/express/lib/router/index.js:317:13)
    at /var/task/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/var/task/node_modules/express/lib/router/index.js:335:12)
    at next (/var/task/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/var/task/node_modules/express/lib/router/index.js:174:3)
    at EventEmitter.handle (/var/task/node_modules/express/lib/application.js:174:10)
    at finish.then (/var/task/node_modules/serverless-http/serverless-http.js:36:13)

Steps to reproduce

Setup a simple serverless-http service on AWS Lambda:

const express = require('express');
const serverless = require('serverless-http');
const bugsnag = require('bugsnag');

const app = express();

// Initialize bugsnag
bugsnag.register(process.env.BUGSNAG_TOKEN, {
  releaseStage: process.env.NODE_ENV,
  notifyReleaseStages: ['staging']
});

app.use(bugsnag.requestHandler);

app.post('/', auth, (req, res, next) => {
  return res.json({});
});

app.use(bugsnag.errorHandler);

module.exports.handler = serverless(app);

Version

  • Node 6.10
  • serverless-http 1.5.2
  • bugsnag 2.1.2
@bengourley
Copy link
Contributor

Hi @jguepin, thanks for the report. I'll get this looked into – I'm sure the workaround on our part is pretty simple.

Do you think this it's also worth posting a bug on dougmoscrop/serverless-http? I would imagine a fair amount of people/middleware for connect/express are using req.connection.address() in some way. It looks like it stubs a socketobject here to pass to the HTTP IncomingMessage class which is incomplete…

I guess the inbound TCP connection is not available to a Lambda function, but is there something else useful we could snag here?

@jguepin
Copy link
Contributor Author

jguepin commented Feb 12, 2018

Hello @bengourley, thanks for the reply!

Indeed, I think the error could be fixed on serverless-http side, I just opened an issue on the repo.

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

No branches or pull requests

2 participants