Migration from CLS to CLS-hooked time outs requests
zatziky opened this issue · comments
I don't know how to describe this issue and hope that you'll give me some hints of what is going on. Any, really any hints are highly appreciated as I can't debug the app to give me any useful info whatsoever. (It seems like a limit in my skills. :)
Background
Since we are using async/await, in our logging lib we have migrated from CLS to CLS-hooked. It fixed the context and we could reach any values needed again. However, when running tests, they started to time-out and the overall app started to react strangely.
All the migration meant only replacement of const continuationStorage = require('continuation-local-storage') // v3.2.1
for const continuationStorage = require('cls-hooked') // v4.2.2
.
Node Versions tested
We have tested against these versions:
- Node 10.14.2
- Node 11.2.0
How do we use CLS?
- This file takes care of context creation. An excerpt:
const continuationStorage = require('cls-hooked')
const createNamespace = continuationStorage.createNamespace
const getNamespace = continuationStorage.getNamespace
const NSP_REQUEST = 'logzio-node-debug-request'
const KEY_MDC = 'mdc'
const requestNamespace = createNamespace(NSP_REQUEST)
function createContext(next) {
const mdc = getAll()
const mdcCopy = Object.assign({}, mdc)
requestNamespace.run(() => {
requestNamespace.set(KEY_MDC, mdcCopy)
next()
})
}
- We create a new context for every incoming request. We're using socket.io
// MDC i
const MDC = require('logzio-node-debug').MDC
socket.use((packet, next) => {
MDC.createContext(() => {
MDC.put('key', 'value')
next()
})
})
- We also put other values during code execution:
const MDC = require('logzio-node-debug').MDC
MDC.put('key2', 'value2')
Question
Is this a bug? Are we doing something wrong?
I managed to identify that the problems happen only with database tests. We are using mysqljs/mysql. Is it possible that it handles queueing improperly?