Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node CLS context drops during execution of a request

I am using https://github.com/jeff-lewis/cls-hooked for preserving execution context across async callbacks. I see context dropping during the life span of a request.

I am aware of https://github.com/nodejs/diagnostics/blob/master/tracing/AsyncHooks/problematic-modules.md modules that break async continuity.

How can I find out what other modules are breaking my async continuity? The app is a express based node.js server.

like image 332
Abhishek Avatar asked May 16 '18 23:05

Abhishek


1 Answers

I finally figured out this after I added logging statements throughout my code and realized that context was being dropped at database calls, turns out I was using https://github.com/datastax/nodejs-driver which does connection pooling internally which causes the context drop.

const cassandra = require('cassandra-driver')

let c = new cassandra.Client(// options here...)

c.execute(query, params, options, namespace.bind(function() {
    // This callback will now inherit the right parent context
}))

More information about userland queuing problem:

https://docs.google.com/document/d/1tlQ0R6wQFGqCS5KeIw0ddoLbaSYx6aU7vyXOkv-wvlM/edit https://github.com/othiym23/node-continuation-local-storage/issues/59

like image 132
Abhishek Avatar answered Nov 10 '22 13:11

Abhishek