当前位置:网站首页>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 :
边栏推荐
- 5. dish management business development
- 24. 图像拼接大作业
- 【IEEE出版】2022年自然语言处理与信息检索国际会议(ECNLPIR 2022)
- Stack Title: fractions in parentheses
- Uniapp develops a wechat applet to display the map function, and click it to open Gaode or Tencent map.
- JMeter interface test tool foundation - sampler (II)
- The latest entry date of SQL Sever test questions
- Distributed transaction principle and solution
- Simple pricelist style code
- 【IEEE出版】2022年智能交通与未来出行国际会议(CSTFM 2022)
猜你喜欢

How can I solve the problem that the swiper animation animation fails when switching between left and right rotations of the swiper?

Customize the toolbars of the kindeditor editor. Items removes unnecessary toolbars or retains some toolbars

Cookie 、Session、localstorage、Sessionstorage的区别

Multithreaded applications - improve efficiency

What you must know about distributed systems -cap

26.删除有序数组的重复项

Spark提交参数--files的使用

Record the range of data that MySQL update will lock

机械臂速成小指南(零):指南主要内容及分析方法

Uniapp implements the function of clicking to make a call
随机推荐
Stack Title: exclusive time of function
26.删除有序数组的重复项
[resource sharing] the 5th International Conference on civil, architectural and environmental engineering in 2022 (iccaee 2022)
【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)
2. login and exit function development
Pycharm shortcut keys
88. merge ordered arrays
cuda runtime error (801) : Raw out
Quick completion guide for mechanical arm (I): development overview of mechanical arm
The difference between static link library and dynamic link library
Web项目部署
Image click enlargement and adaptive size in the applet rich text
Solve the timeout of Phoenix query of dbeaver SQL client connection
4. classification management business development
Hill sorting graphic explanation + code implementation
Learn how to use PHP to filter special symbols in strings
分布式事务原理以及解决分布式事务方案
Leetcode-929: unique email address
【Energy Reports期刊发表】2022年能源与环境工程国际会议(CFEEE 2022)
[EI分享] 2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)