feat(assist): tried to fix uWS.HttpResponse.onAborted exception
This commit is contained in:
parent
c68bd2b859
commit
58ac2a04ae
3 changed files with 13 additions and 4 deletions
|
|
@ -27,9 +27,14 @@ const respond = function (req, res, data) {
|
|||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(result));
|
||||
} else {
|
||||
res.cork(() => {
|
||||
res.writeStatus('200 OK').writeHeader('Content-Type', 'application/json').end(JSON.stringify(result));
|
||||
});
|
||||
if (!res.aborted) {
|
||||
res.cork(() => {
|
||||
res.writeStatus('200 OK').writeHeader('Content-Type', 'application/json').end(JSON.stringify(result));
|
||||
});
|
||||
} else {
|
||||
logger.debug("response aborted");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const duration = performance.now() - req.startTs;
|
||||
IncreaseTotalRequests();
|
||||
|
|
|
|||
|
|
@ -83,9 +83,11 @@ if (process.env.uws !== "true") {
|
|||
const uWrapper = function (fn) {
|
||||
return (res, req) => {
|
||||
res.id = 1;
|
||||
res.aborted = false;
|
||||
req.startTs = performance.now(); // track request's start timestamp
|
||||
req.method = req.getMethod();
|
||||
res.onAborted(() => {
|
||||
res.aborted = true;
|
||||
onAbortedOrFinishedResponse(res);
|
||||
});
|
||||
return fn(req, res);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,9 @@ const doFetchAllSockets = async function () {
|
|||
}
|
||||
}
|
||||
try {
|
||||
return await io.fetchSockets();
|
||||
let result = await io.fetchSockets();
|
||||
lastKnownResult = result;
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('Error fetching sockets:', error);
|
||||
return lastKnownResult;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue