From 088e25cbb0de5341f5a3870478aee16f9e20813f Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 11 Aug 2021 12:27:51 -0700 Subject: [PATCH] New config option cwmp.downloadSuccessOnTimeout Workaround for CPEs that neglect to send TransferComplete message after a successful download. --- lib/session.ts | 52 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/session.ts b/lib/session.ts index dd9b9c0..ebbd4ba 100644 --- a/lib/session.ts +++ b/lib/session.ts @@ -458,22 +458,50 @@ export async function timeoutOperations( (e) => configContextCallback(sessionContext, e) ) * 1000; - if (sessionContext.timestamp > operation.timestamp + DOWNLOAD_TIMEOUT) { - delete sessionContext.operations[commandKey]; - if (!sessionContext.operationsTouched) - sessionContext.operationsTouched = {}; - sessionContext.operationsTouched[commandKey] = 1; + if (sessionContext.timestamp < operation.timestamp + DOWNLOAD_TIMEOUT) + continue; - faults.push({ - code: "timeout", - message: "Download operation timed out", - timestamp: operation.timestamp, - }); + logger.accessWarn({ + sessionContext: sessionContext, + message: "Download operation timed out", + commandKey: commandKey, + }); - operations.push(operation); + const SUCCESS_ON_TIMEOUT = +localCache.getConfig( + sessionContext.cacheSnapshot, + "cwmp.downloadSuccessOnTimeout", + {}, + sessionContext.timestamp, + (e) => configContextCallback(sessionContext, e) + ); - revertDownloadParameters(sessionContext, operation.args.instance); + if (SUCCESS_ON_TIMEOUT) { + const r = { + name: "TransferComplete" as const, + commandKey: commandKey, + startTime: 0, + completeTime: 0, + }; + + // Call transferComplete code and ignore the response + await transferComplete(sessionContext, r); + continue; } + + delete sessionContext.operations[commandKey]; + if (!sessionContext.operationsTouched) + sessionContext.operationsTouched = {}; + sessionContext.operationsTouched[commandKey] = 1; + + faults.push({ + code: "timeout", + message: "Download operation timed out", + timestamp: operation.timestamp, + }); + + operations.push(operation); + + revertDownloadParameters(sessionContext, operation.args.instance); } return { faults, operations };