镜像自地址
https://git.coolaj86.com/coolaj86/telebit.js.git
已同步 2025-07-06 19:26:33 +00:00
use .destroy
if .end
fails to close connection
这个提交包含在:
父节点
d6cad7cb65
当前提交
5e8d99a34c
46
wsclient.js
46
wsclient.js
@ -6,6 +6,12 @@ var PromiseA = require('bluebird');
|
||||
var sni = require('sni');
|
||||
var Packer = require('tunnel-packer');
|
||||
|
||||
function timeoutPromise(duration) {
|
||||
return new PromiseA(function (resolve) {
|
||||
setTimeout(resolve, duration);
|
||||
});
|
||||
}
|
||||
|
||||
function run(copts) {
|
||||
var activityTimeout = copts.activityTimeout || 2*60*1000;
|
||||
var pongTimeout = copts.pongTimeout || 10*1000;
|
||||
@ -38,37 +44,35 @@ function run(copts) {
|
||||
}
|
||||
|
||||
console.log('[closeSingle]', cid);
|
||||
try {
|
||||
PromiseA.resolve()
|
||||
.then(function () {
|
||||
localclients[cid].end();
|
||||
setTimeout(function () {
|
||||
return timeoutPromise(500);
|
||||
})
|
||||
.then(function () {
|
||||
if (localclients[cid]) {
|
||||
console.warn('[closeSingle]', cid, 'connection still present');
|
||||
console.warn('[closeSingle]', cid, 'connection still present after calling `end`');
|
||||
localclients[cid].destroy();
|
||||
return timeoutPromise(500);
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
if (localclients[cid]) {
|
||||
console.error('[closeSingle]', cid, 'connection still present after calling `destroy`');
|
||||
delete localclients[cid];
|
||||
}
|
||||
}, 500);
|
||||
} catch (err) {
|
||||
console.warn('[closeSingle] failed to close connection', cid, err);
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error('[closeSingle] failed to close connection', cid, err);
|
||||
delete localclients[cid];
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
, closeAll: function () {
|
||||
console.log('[closeAll]');
|
||||
Object.keys(localclients).forEach(function (cid) {
|
||||
try {
|
||||
localclients[cid].end();
|
||||
} catch (err) {
|
||||
console.warn('[closeAll] failed to close connection', cid, err);
|
||||
}
|
||||
clientHandlers.closeSingle(cid);
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
Object.keys(localclients).forEach(function (cid) {
|
||||
if (localclients[cid]) {
|
||||
console.warn('[closeAll]', cid, 'connection still present');
|
||||
delete localclients[cid];
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
|
||||
, count: function () {
|
||||
|
正在加载...
x
在新工单中引用
屏蔽一个用户