【问题标题】:Node CLS context drops during execution of a request执行请求期间节点 CLS 上下文丢失
【发布时间】:2018-10-27 03:15:50
【问题描述】:

我使用https://github.com/jeff-lewis/cls-hooked 来跨异步回调保留执行上下文。我看到上下文在请求的生命周期内下降。

我知道 https://github.com/nodejs/diagnostics/blob/master/tracing/AsyncHooks/problematic-modules.md 模块会破坏异步连续性。

如何找出哪些其他模块破坏了我的异步连续性? 该应用程序是基于 express 的 node.js 服务器。

【问题讨论】:

    标签: node.js express socket.io node-local-storage continuation-local-storag


    【解决方案1】:

    在我在整个代码中添加日志语句并意识到在数据库调用时上下文被丢弃后,我终于明白了这一点,结果我使用的是https://github.com/datastax/nodejs-driver,它在内部进行连接池,导致上下文丢弃。

    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
    }))
    

    关于用户态排队问题的更多信息:

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

    【讨论】:

    • 在涉及连接池的 mysql db 中遇到了同样的问题。我还使用节点 js 的异步钩子编写了自己的实现,但面临同样的上下文删除问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 2019-06-17
    • 2012-09-06
    相关资源
    最近更新 更多