Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception in connection.end() for MySQL Dialect #1853

Closed
wants to merge 1 commit into from

Conversation

I00000
Copy link

@I00000 I00000 commented Jan 7, 2017

fix for #1798

@eelhigu: please review?

@elhigu
Copy link
Member

elhigu commented Jan 8, 2017

I'm on my mobile so I cannot be browsing the code right now to verify if this is ok... do you know why that removeAllListeners call is there and will there be event listeners left if its not called anymore? @wubzz do you know anything about this?

@I00000
Copy link
Author

I00000 commented Jan 10, 2017

hi @tgriesser,

In your following commit 7069ce5#diff-b0704a0e57b09b0c3670a2c6b953da1d, you have added that connection.removeAllListeners(), do you know why because in my scenario, it crashes my server and I don't really understand why this layer is responsible for cleaning all listeners.

Thanks in advance for your clarification

@wubzz
Copy link
Member

wubzz commented Mar 14, 2017

@elhigu @I00000 Sorry for the slow response.. I know we've had issues about this in the past, specifically for mysql. I'm not sure why .removeAllListeners() was added tbh, I'd think calling .end() makes this call redundant. Only @tgriesser would know the answer to this, so I can't really make a decision here.

However, I don't quite understand why the following would not work:

connection.end((err) => {
       connection.removeAllListeners();
        if (err) connection.__knex__disposed = err
});

What error remains after this change? Since the event listeners aren't removed until after .end() has been called, surely it should work..

I'm also inclined to agree with #1691 reference to the Node docs:
Note that it is bad practice to remove listeners added elsewhere in the code

@I00000
Copy link
Author

I00000 commented Jun 23, 2017

@wubzz: node crahes

novemberborn added a commit to novemberborn/knex that referenced this pull request Jul 28, 2017
Connections created by MySQL2 driver transition to broken state when
network errors or timeouts occur. This condition is not visible to the
connection pool in Knex.

If Knex detects a timeout and tries to close a connection, this causes
an uncaught exception from MySQL2. Similarly the connection pool never
realizes the connection is in a broken state, and thus will never
replace it.

Unfortunately the MySQL2 connection does not expose a state, but it can
be inferred by checking for `connection._fatalError`.

Fixes knex#1853
@novemberborn
Copy link
Contributor

I think the problem is that mysql2 transitions connections to a broken state, and the dialect in Knex does not recognize this. #2175 seems to fix it for me.

@elhigu
Copy link
Member

elhigu commented Aug 15, 2017

Closing in favor of #2175

@elhigu elhigu closed this Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants