当前位置:网站首页>The nodejs service global timeout callback failed to get process Domain problem
The nodejs service global timeout callback failed to get process Domain problem
2022-06-24 10:43:00 【Mongolia Shangdan 2】
There is a problem with our server , When triggered express After global timeout for , stay server.setTimeout In the callback of ,process.domain yes undefined.
As we will generate each visit reqId、 user id Wait for the information to be saved in process.domain in . If you can't get it process.domain, It is difficult for us to find out the error log in the massive logs , It makes it difficult to troubleshoot online problems .
Here is the simplified code :
const domain = require('domain');
const express = require('express');
const app = express();
const http = require('http');
const sleep = (ts) => (new Promise(resolve => setTimeout(resolve, ts)))
app.use((req, res, next) => {
const d = domain.create();
d.id = 999999;
d.add(req);
d.add(res);
d.run(next);
});
let testRouter = express.Router();
testRouter.get('/', async function (req, res) {
await sleep(2000);// etc. 2 second , Let the program enter the global timeout logic
res.send('hello world!');
});
app.use('/test', testRouter);
const server = http.createServer(app).listen(3000, '127.0.0.1', () => {});
server.setTimeout(1000, (socket) => {
console.log(process.domain);// The result here is undefined
});
stay stackoverflow in , I saw an old man saying it was domain Scope problem , You must mount the correct scope to domain in . I tried , Found a solution .
So what we wrote was :
d.add(req); d.add(res);
The solution is to req.socket Also added domain Go to the scope , That is, the following writing :
d.add(req); d.add(res); d.add(req.socket);
I don't understand this yet domain What is the scope , We will continue to study it later domain Source code of the component :
边栏推荐
- Baidu online disk download has been in the process of requesting solutions
- 126. 单词接龙 II BFS
- JMeter接口测试工具基础— 使用Badboy录制JMeter脚本
- 牛客-TOP101-BM29
- Hill sorting graphic explanation + code implementation
- Record the range of data that MySQL update will lock
- Svg+js drag slider round progress bar
- Charles packet capturing tool tutorial
- Uniapp implements the function of clicking to make a call
- Appium自动化测试基础 — 移动端测试环境搭建(一)
猜你喜欢

Flink checkpoint and savepoint

88. merge ordered arrays

分布式事务原理以及解决分布式事务方案

Cookie 、Session、localstorage、Sessionstorage的区别

Charles packet capturing tool tutorial

Record the range of data that MySQL update will lock

6. package management business development

【JS逆向分享】某个网站社区信息
![[resource sharing] 2022 International Conference on Environmental Engineering and Biotechnology (coeeb 2022)](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[resource sharing] 2022 International Conference on Environmental Engineering and Biotechnology (coeeb 2022)
![[JS reverse sharing] community information of a website](/img/71/8b77c6d229b1a8301a55dada08b74f.png)
[JS reverse sharing] community information of a website
随机推荐
numpy. logical_ and()
3. addition, deletion, modification and query of employees
Dedecms template file explanation and homepage label replacement
Uniapp implements the function of clicking to make a call
程序员在技术之外,还要掌握一个技能——自我营销能力
機械臂速成小指南(二):機械臂的應用
splice()方法的使用介绍
[IEEE] International Conference on naturallanguageprocessing and information retrieval (ecnlpir 2022)
88.合并有序数组
Spark submission parameter -- use of files
SSM integration
js中对象合并的4种方式,对象合并的4种方法
Web project deployment
HBuilder制作英雄皮肤抽奖小游戏
Leetcode-929: unique email address
283.移动零
2. login and exit function development
Resolved: methods with the same name as their class will not be constructors in
Besides technology, programmers also need to master a skill - self marketing ability
A method to solve the self-adaptive width and height of the internal picture of rich text label in wechat applet