Mysql: TypeError: domain.enter is not a function on aborted connection

Created on 27 Feb 2018  路  13Comments  路  Source: mysqljs/mysql

I'm not sure if this issue derives from this library, but I know it's at least correlated, so I'm hoping someone can help me out.

If I force an aborted connection in my app (like refreshing the browser during the app's handshake with the db), node spits out the following and crashes out:

events.js:155
domain.enter();
       ^
TypeError: domain.enter is not a function
 at IncomingMessage.emit (events.js:155:12)
   at abortIncoming (_http_server.js:427:9)
    at socketOnEnd (_http_server.js:443:5)
   at Socket.emit (events.js:165:20)
  at endReadableNT (_stream_readable.js:1101:12)
   at process._tickCallback (internal/process/next_tick.js:152:19)

Express is also in the mix, and given the files in that trace one would think something is underlying there, but I can only duplicate the error while MySQL is involved.

Even if I can't completely correct this issue, I'd like to at least handle it gracefully, but I can't even figure out where it's erupting from to do that.

Thanks!

Most helpful comment

Just to follow up on this, I finally found out the issue, and it indeed was unrelated to this library. A poorly written third-party module was assigning itself to the domain key of the Express request object, which is reserved for that library's use of node native Domains. I was only getting the error intermittently when an unrelated async issue with mysql connections within an express route was occurring, leading to me thinking mysql was implicated. Pretty obscure, but thought I'd post in the minuscule chance anyone else out there hits the same combination of factors.

All 13 comments

The stack trace is originating from within Node.js core files. What's the exact version of the Node.js runtime you're using?

It's v9.5.0, coming out of the node:latest docker package.

Cool. So we haven't tested this library with Node.js 9.x yet, so it's possible there could be something we need to change to properly support Node.js 9.x, not sure. That being said, I believe that Node.js 9.x broke some domains event things in 9.2.0 and fixed it again in 9.6.1. Can you try out either a version prior to 9.2.0 or version 9.6.1 to see if the issue is resolved?

Sorry, I think I have the version numbers off above; should say:

That being said, I believe that Node.js 9.x broke some domains event things in 9.5.0 and fixed it again in 9.6.1. Can you try out either a version prior to 9.5.0 or version 9.6.1 to see if the issue is resolved?

So I just tried 9.6.1, and am having the same problem, albeit with a slightly different stack trace:

                        | domain.js:438
                        |   domain.enter();
                        |          ^
                        | 
                        | TypeError: domain.enter is not a function
                        |     at IncomingMessage.emit (domain.js:438:10)
                        |     at abortIncoming (_http_server.js:441:9)
                        |     at socketOnEnd (_http_server.js:457:5)
                        |     at Socket.emit (events.js:132:15)
                        |     at Socket.emit (domain.js:421:20)
                        |     at endReadableNT (_stream_readable.js:1101:12)
                        |     at process._tickCallback (internal/process/next_tick.js:152:19)

Just for fun, let me also try it with the latest 8.x just to see what happens.

Yes same error again on 8 latest as well unfortunately. I'll include my output from both of my docker containers, the only other info I have is the abort warning from the DB:

api_1                        | events.js:199
api_1                        |     domain.enter();
api_1                        |            ^
api_1                        | 
api_1                        | TypeError: domain.enter is not a function
api_1                        |     at IncomingMessage.emit (events.js:199:12)
api_1                        |     at abortIncoming (_http_server.js:412:9)
api_1                        |     at socketOnEnd (_http_server.js:428:5)
api_1                        |     at emitNone (events.js:111:20)
api_1                        |     at Socket.emit (events.js:208:7)
api_1                        |     at endReadableNT (_stream_readable.js:1055:12)
api_1                        |     at _combinedTickCallback (internal/process/next_tick.js:138:11)
api_1                        |     at process._tickDomainCallback (internal/process/next_tick.js:218:9)
db                   | 2018-02-27T16:52:02.881067Z 5 [Note] Aborted connection 5 to db: 'db' user: 'xxxxxxxx' host: 'xxxxxxxxxx' (Got an error reading communication packets)

Very strange. I really have no idea why this would happen and the stack traces don't help at all, because the domain variable is private to in events.js so not sure how this module could be changing that.

I would like to get something to plug a debugger to to walk through.

Is there any way you can provide full code and instructions so I can reproduce the issue?

Unfortunately it's a pretty low-level piece of a large platform so I'm unable to post the full code. Your comment did however remind me that I should probably get my Node debugger back up and working again so I might be able to try that on my end. It may not be for a few days though, if you're alright with keeping this ticket open for a bit I'd be up for posting whatever further info I can find by stepping through things as soon as I'm able. Appreciate the help in any case!

Hi @dvodonnell I've been poking at this a bit and haven't been able to trigger it so far, so not sure yet why it's happening and how to resolve :(

Hi @dvodonnell would it be possible to try the current master branch now and see if the issue is still present?

I'm going to close since I never heard back. If you're still having issues, please let us know though :+1:

Just to follow up on this, I finally found out the issue, and it indeed was unrelated to this library. A poorly written third-party module was assigning itself to the domain key of the Express request object, which is reserved for that library's use of node native Domains. I was only getting the error intermittently when an unrelated async issue with mysql connections within an express route was occurring, leading to me thinking mysql was implicated. Pretty obscure, but thought I'd post in the minuscule chance anyone else out there hits the same combination of factors.

@dvodonnell which third-party module did you narrow it down to?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macias picture macias  路  3Comments

flowl picture flowl  路  4Comments

whatthehell232 picture whatthehell232  路  3Comments

EdoardoPedrotti picture EdoardoPedrotti  路  3Comments

hohozhao picture hohozhao  路  4Comments