pinojs/pino

Logging Axios error crashes server

Closed this issue · 7 comments

Hello

I'm using Adonisjs which uses PIno under the hood to log errors. I'm using axios to make some requests but I noticed that when an error is thrown and I attempt to log it it crashes the app.

node version 18.18.0
Pino version 6.14.0

return axios
        .post(`${process.env.API_URL}/some-slug`, {
          ...data,
        })
        .then(({ data }) => {
          return data
        })
        .catch((err: any) => {
          console.log('error posting ')
          console.error(err)  // <--- does not crash 
          logger.error(err) // <--- This line crashes the server 
          return response.badRequest({ message: err.message })
        })

Here is the stack trace given

/Users/me/.nvm/versions/node/v18.18.0/bin/node[71014]: ../src/tcp_wrap.cc:155:static void node::TCPWrap::New(const FunctionCallbackInfo<v8::Value> &): Assertion `args[0]->IsInt32()' failed.
 1: 0x1025be045 node::Abort() [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 2: 0x1025bde01 node::Assert(node::AssertionInfo const&) [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 3: 0x102694079 node::TCPWrap::New(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 4: 0x1027ad498 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 5: 0x1027acc54 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<true>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 6: 0x1027ac5fb v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 7: 0x1030f2cf9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 8: 0x10307478c Builtins_JSBuiltinsConstructStub [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
 9: 0x103190cff Builtins_ConstructHandler [/Users/me/.nvm/versions/node/v18.18.0/bin/node]
10: 0x103076c50 Builtins_InterpreterEntryTrampoline [/Users/me/.nvm/versions/node/v18.18.0/bin/node]

Please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).

@jsumners here you go https://github.com/palfaro91/log-error/

npm install
npm run dev
then access the root / url and the server should crash when logging the error

[ info ]  building project...
[ info ]  starting http server...

   Exception: E_MISSING_ENV_VALUE: Missing environment variable "APP_KEY"

   at Object.<anonymous> /Users/matteo/tmp/log-error/server.ts:19
   14|  import sourceMapSupport from 'source-map-support'
   15|  import { Ignitor } from '@adonisjs/core/build/standalone'
   16|
   17|  sourceMapSupport.install({ handleUncaughtExceptions: false })
   18|
 ❯ 19|  new Ignitor(__dirname).httpServer().start()
   20|

   ⁃ ensureValue
     /Users/matteo/tmp/log-error/node_modules/@adonisjs/env/build/src/Schema/helpers.js:26
   ⁃ Object.validate [as APP_KEY]
     /Users/matteo/tmp/log-error/node_modules/@adonisjs/env/build/src/Schema/string.js:45
   ⁃ anonymous
     /Users/matteo/tmp/log-error/node_modules/@adonisjs/env/build/src/Env/index.js:87

[ warn ]  Underlying HTTP server died with "0 code"
[ info ]  watching file system for changes

I would recommend you to provide a reproduction with just pino and axios.

@mcollina My apologies. I have added the missing file and tested it to ensure it will run.

A few notes:

  1. please provide a reproduction without Adonis, complex TS setups, or any other dependencies. It's very hard to track down what's happening
  2. you are using a very old version of pino that is out of support
  3. Axios errors are very complex and they include a lot of things. My guess is that pino does something they do not like. You might want to use a custom serializer to handle those, and figure out what's the problem.

The crash disappears by disabling prettyPrint because it's hitting some problematic lines that we have already fixed in latest releases of pino. Therefore, there is nothing we can do here for you.

@mcollina Alright thank you for the info. 🙏 I'll reach out to the Adonis team about getting the Pinio package updated.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.