It would be nice to at least document what is the reason node-mysql2 is using process.nextTick to process the queries.
I am sure there is a good reason for it, probably something to do with sending packets in batches, though it comes at a high cost of DX. The stack traces are completely useless. It would be nice to mention this in the documentation and maybe even have an option to disable it when working in NODE_ENV=development.
I can't remember exactly, I think it's used instead of try/catch around callback invocation. It might be better for performance, but I'd really like to review this again, I thing in modern V8 try/catch is not as bad as before
Okay. I can I have a look into this.
I think commit b73ac9868804b603a0ab6df6129cf3682476d118 is where they were added.
I'm pretty sure this is no longer required as perf optimisation:
https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax
When I said perf optimisation, I thought that you were doing something along the lines of
I cannot find what is causing this entry in the stack trace:
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
This is where the stack traces end. I've gone through every dependency in the node_modules that uses nextTick. Nothing.
Adding debugger to the next_tick does not help either.
Any suggestions?
I ended up logging the queries before they are executed. This solves the most of the issues for me from the DX perspective.
I am killing this issue as the nextTick as it is used in mysql2 does not have direct effect to the stack traces.
p.s. I am using node-mysql2 fork with all nextTick instances stripped. It appears to work with no side-effects. I am happy to raise a PR for it, though I am unsure if there are any use cases that I am overlooking.
We're having issues getting a reasonable call stack on errors because of this, why not just open this and remove all nextTicks from the code?
do you want to volunteer to do this @lillem4n ? I do agree that nextTick no longer needed
I'd love too, but do not have the free time. Trying to sqeeze this in on a client project. If I manage that, I'll revisit this. :)
Most helpful comment
I'd love too, but do not have the free time. Trying to sqeeze this in on a client project. If I manage that, I'll revisit this. :)