Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Error: Cannot read property 'nameState' of null #32

Closed
jgeurts opened this issue Jun 19, 2020 · 5 comments · Fixed by #70
Closed

Error: Cannot read property 'nameState' of null #32

jgeurts opened this issue Jun 19, 2020 · 5 comments · Fixed by #70
Labels

Comments

@jgeurts
Copy link
Contributor

jgeurts commented Jun 19, 2020

Hi, this is a bit hard for me to diagnose, so I'm hoping posting here might help uncover the root cause. We've been seeing random errors coming from what seems to be this project, but it might be more related to Koa Router... The errors have been happening for the last few weeks and they look like:

TypeError: Cannot read property 'nameState' of null
    at Object.set (/var/www/html/node_modules/@newrelic/koa/lib/instrumentation.js:94:12)
    at dispatch (/var/www/html/node_modules/@koa/router/lib/router.js:353:23)
    at wrapper (/var/www/html/node_modules/newrelic/lib/shim/shim.js:947:24)
    at dispatch (/var/www/html/node_modules/koa-compose/index.js:42:32)
    ...

We're currently running @koa/router v9.0.1, @newrelic/koa v3.0.0, koa v2.12.0, and newrelic v6.9.0 on the latest Node.js v10 LTS. I'm not sure what else I can provide or really how to reproduce this issue, but I will help however I can!

@michaelgoin
Copy link
Member

Hi @jgeurts!

Sorry you are running into issues. Looking at the code, I think we have two issues here.

First, it looks like we don't protect against transaction state loss in our instrumentation your stack trace points to. The code is assuming const tx = shim.agent.tracer.getTransaction() is always successful, which may not be the case if something else has gone wrong. If we lose state, or the transaction has already ended, we'll return null. I'm really surprised you are the first to run into this. I'll go ahead and create a new issue for that.

Second, I'm going to assume based on the above the transaction/segment state has been lost or the transaction has been ended prior to this code. That may be due to changes in @koa/router breaking assumptions/mechanisms our instrumentation relies on or some other framework may be interfering with our ability to keep state. I'm guessing once the first item is fixed, you'll find other issues with regards to naming.

To get the state loss problem figured-out/resolved, we typically need to do more in-depth information gathering, etc. by leveraging our great support team. I would recommend going through the official support channels via: https://support.newrelic.com/ so we can make sure we are as responsive as possible. You may or may not want to wait for us to fix the above to see how it impacts your app before doing so.

Thank you,

Michael

@jgeurts
Copy link
Contributor Author

jgeurts commented Jun 23, 2020

Sounds good, thank you!

@fadliawan
Copy link

Hello,

I ran into this issue as well today. Here's my environment:

  1. Node v12 running on Alpine node:12.18.3-alpine3.12 official image as base
  2. newrelic@6.13.0
  3. koa@2.13.0
  4. koa-router@8.0.8
  5. koa-redis@4.0.1

Stack trace:

TypeError: Cannot read property 'nameState' of null
    at Object.set (/app/node_modules/@newrelic/koa/lib/instrumentation.js:99:12)
    at dispatch (/app/node_modules/koa-router/lib/router.js:358:23)
    at wrapper (/app/node_modules/newrelic/lib/shim/shim.js:936:24)
    at dispatch (/app/node_modules/koa-compose/index.js:42:32)
    ...
    at tryCatch (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:293:22)
    at Generator.next (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:118:21)
    ...
    at wrapper (/app/node_modules/newrelic/lib/shim/shim.js:936:24)
    at dispatch (/app/node_modules/koa-compose/index.js:42:32)
    ...
    at tryCatch (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:293:22)
    at Generator.next (/app/node_modules/koa-redis/node_modules/regenerator-runtime/runtime.js:118:21)
    ...
    at new Promise (<anonymous>)

@astormnewrelic
Copy link
Contributor

Thank you for reporting that issue @fadliawan -- this definitely looks like a bug. The next best steps towards fixing this will be for us to be able to reproduce it. To that end we have a few questions -- if you could answers as many of these as possible it would go a long way towards us being able to investigate this further.

  • Are you able to reproduce this issue whenever you want, or is it something that happens occasionally/seemingly-at-random?
  • Is this a recoverable error, or does it crash the node process?
  • Which logs are you seeing this in?
  • Does this happen only when processing certain routes? Or does it happen for every route?
  • If you temporarily disable koa-redis for your session storage, does the problem remain?

With these answers in hand we'll have a better idea of where to focus our debugging efforts.

@iaibai
Copy link

iaibai commented Sep 8, 2020

Hi, we're getting this error too. We're trying to run koa serverlessly though - using the serverless framework, on AWS lambda - so I appreciate there may be more to the problem that we're experiencing.

Even if we cut the lambda down to the bare minimum, we get the error;

TypeError: Cannot read property 'nameState' of null
       at Object.set (/var/task/node_modules/@newrelic/koa/lib/instrumentation.js:99:12)
       at dispatch (/var/task/node_modules/@koa/router/lib/router.js:358:23)
       at wrapper (/var/task/node_modules/newrelic/lib/shim/shim.js:936:24)
       at dispatch (/var/task/node_modules/koa-compose/index.js:42:32)
       at /var/task/node_modules/koa-compose/index.js:34:12
       at Application.handleRequest (/var/task/node_modules/koa/lib/application.js:166:12)
       at handleRequest (/var/task/node_modules/koa/lib/application.js:148:19)
       at /var/task/node_modules/serverless-http/lib/framework/get-framework.js:9:5
       at /var/task/node_modules/serverless-http/serverless-http.js:19:28
       at async Runtime.handler (/var/task/node_modules/serverless-http/lib/provider/aws/index.js:11:22) 

The bare minimum being;


'use strict';
require("newrelic");
import * as Router from "@koa/router";
const serverless = require('serverless-http/serverless-http');
import * as Koa from "koa";
const app = new Koa();
app.proxy = true;

const router = new Router();

router.get('/',  (ctx: Koa.Context) => {
    ctx.body = "nrtest";
});

app.use(router.routes());
app.use(router.allowedMethods());
module.exports.main = serverless(app);

However, it does not give this error if we go to a route that doesn't exist. In that case we get the expected "404 / Not Found".

To answer your questions above,

  • It's happening on every request, though the stack trace differs depending on the route.
  • I don't think it crashes the node process ... at least it doesn't seem like our lambda has to 'cold start' between requests. Also, we get a proper "500 Internal Server Error" response which I don't think we'd see if the lambda fully failed.
  • The error is appearing in our cloudwatch logs for the lambda.

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

Successfully merging a pull request may close this issue.

5 participants