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
Bluebird remove return, reflect, fromCallback #3483
Conversation
It seems to be failing on Node 12 consistently. |
Hm, strange errors, I will research this |
So error got passed through try-catch, really strange
|
connection.end called after last command fail, which cleared all events, so 'error' event emitted to nowhere and emitted as unhandled error |
Before node12
Was
Now
Bluebird solution worked because of additional microtask from .catch? |
@kibertoad have you any ideas to resolve this? |
@maximelkin Can we add additional listener to catch the error when it is thrown asynchronously? |
@kibertoad can this trigger leaks? When to unsubscribe this listener? |
7069ce5 <- here removeAllListeners added |
@kibertoad that do you think? |
return await end(); | ||
} catch (err) { | ||
connection.__knex__disposed = err; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that finally removeAllListeners really unnecessary? Is there test somewhere, which fails if connection has listeners after disposal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run knex-stress-test for a some minutes (with process.memoryUsage().heapUsed logging)
memory usage is stable, so no leak introduced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds promising. Did you try it with both mysql and mysql2 drivers?
Though if that listener removal is not necessary, shouldn't this function just return end() and leave it to caller to set __knex__disposed like in every other driver
One more thing... if that Error: This socket has been ended by the other party
is now not leaked, I suppose that error is still happening, but it is ignored somewhere (by existence of some event handler maybe). So when it is ignored how does that get recorded to connection.__knex__disposed
or does it even matter...
Also I'm pretty confused how is it possible that error is leaking and where that leak is happening exactly (stack trace showed lib/dialects/mysql/index.js:85:20, but then it should have been handled by caller's error handler). And when it is leaked why caller's error handling is not catching it? That was an async function after all.
This is a part of really fundamental functionality of knex and may cause hard to catch failures for huge user base if it is not working properly.I would really like to understand the problem properly before trying to patch it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I easily reproduce the original error to investigate it a bit more? Did it happen in some very specific test or every time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Install 12 node
Add finally block with removeAllListeners
run test "#2321 dead connections are not evicted from pool"
@elhigu why? |
Because its addition didn't look like an accident and there was not proper investigation done, if it can be removed or not. |
As temporal solution we can add delay before removeAllListeners, so it would work like before |
@maximelkin I believe https://lodash.com/docs/4.17.14#defer does exactly this? |
@kibertoad yes |
But i still think what we should review removeAllListeners usage, maybe in separate issue |
But with defer, to match all behavior
@elhigu @kibertoad done |
No description provided.