gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (a754f92d7 -> 490ef893e)


From: gnunet
Subject: [taler-wallet-core] branch master updated (a754f92d7 -> 490ef893e)
Date: Thu, 15 Feb 2024 23:51:36 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-core.

    from a754f92d7 fix logging
     new 42a7a31fb -logging, reset task retries properly for exchanges
     new 490ef893e taler-util: cancellation and timeouts on NodeJS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 packages/taler-util/src/http-impl.node.ts          | 68 ++++++++++++++++++++--
 .../taler-wallet-core/src/operations/exchanges.ts  |  6 +-
 2 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/packages/taler-util/src/http-impl.node.ts 
b/packages/taler-util/src/http-impl.node.ts
index dec4e3f31..ea2309504 100644
--- a/packages/taler-util/src/http-impl.node.ts
+++ b/packages/taler-util/src/http-impl.node.ts
@@ -19,17 +19,17 @@
 /**
  * Imports.
  */
-import * as net from "node:net";
-import type { ClientRequest, IncomingMessage } from "node:http";
 import {
   FollowOptions,
   RedirectableRequest,
   http,
   https,
 } from "follow-redirects";
+import type { ClientRequest, IncomingMessage } from "node:http";
 import { RequestOptions } from "node:http";
+import * as net from "node:net";
 import { TalerError } from "./errors.js";
-import { encodeBody, getDefaultHeaders, HttpLibArgs } from "./http-common.js";
+import { HttpLibArgs, encodeBody, getDefaultHeaders } from "./http-common.js";
 import {
   DEFAULT_REQUEST_TIMEOUT_MS,
   Headers,
@@ -41,8 +41,8 @@ import {
   Logger,
   RequestThrottler,
   TalerErrorCode,
-  typedArrayConcat,
   URL,
+  typedArrayConcat,
 } from "./index.js";
 
 // Work around a node v20.0.0, v20.1.0, and v20.2.0 bug. The issue was fixed
@@ -122,6 +122,8 @@ export class HttpLibImpl implements HttpRequestLibrary {
 
     const requestHeadersMap = { ...getDefaultHeaders(method), ...opt?.headers 
};
 
+    logger.trace(`request timeout ${timeoutMs} ms`);
+
     let reqBody: ArrayBuffer | undefined;
 
     if (
@@ -182,6 +184,18 @@ export class HttpLibImpl implements HttpRequestLibrary {
       );
     }
 
+    let timeoutHandle: NodeJS.Timer | undefined = undefined;
+    let cancelCancelledHandler: (() => void) | undefined = undefined;
+
+    const doCleanup = () => {
+      if (timeoutHandle != null) {
+        clearTimeout(timeoutHandle);
+      }
+      if (cancelCancelledHandler) {
+        cancelCancelledHandler();
+      }
+    };
+
     return new Promise((resolve, reject) => {
       const handler = (res: IncomingMessage) => {
         res.on("data", (d) => {
@@ -217,9 +231,11 @@ export class HttpLibImpl implements HttpRequestLibrary {
               return text;
             },
           };
+          doCleanup();
           resolve(resp);
         });
         res.on("error", (e) => {
+          const code = "code" in e ? e.code : "unknown";
           const err = TalerError.fromDetail(
             TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
             {
@@ -227,8 +243,9 @@ export class HttpLibImpl implements HttpRequestLibrary {
               requestMethod: method,
               httpStatusCode: 0,
             },
-            `Error in HTTP response handler: ${e.message}`,
+            `Error in HTTP response handler: ${code}`,
           );
+          doCleanup();
           reject(err);
         });
       };
@@ -242,7 +259,45 @@ export class HttpLibImpl implements HttpRequestLibrary {
         throw new Error(`unsupported protocol ${options.protocol}`);
       }
 
+      if (timeoutMs != null) {
+        timeoutHandle = setTimeout(() => {
+          logger.info(`request to ${url} timed out`);
+          const err = TalerError.fromDetail(
+            TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
+            {
+              requestUrl: url,
+              requestMethod: method,
+              httpStatusCode: 0,
+            },
+            `Request timed out after ${timeoutMs} ms`,
+          );
+          timeoutHandle = undefined;
+          req.destroy();
+          doCleanup();
+          reject(err);
+          req.destroy();
+        }, timeoutMs);
+      }
+
+      if (opt?.cancellationToken) {
+        cancelCancelledHandler = opt.cancellationToken.onCancelled(() => {
+          const err = TalerError.fromDetail(
+            TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
+            {
+              requestUrl: url,
+              requestMethod: method,
+              httpStatusCode: 0,
+            },
+            `Request cancelled`,
+          );
+          req.destroy();
+          doCleanup();
+          reject(err);
+        });
+      }
+
       req.on("error", (e: Error) => {
+        const code = "code" in e ? e.code : "unknown";
         const err = TalerError.fromDetail(
           TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR,
           {
@@ -250,8 +305,9 @@ export class HttpLibImpl implements HttpRequestLibrary {
             requestMethod: method,
             httpStatusCode: 0,
           },
-          `Error in HTTP request: ${e.message}`,
+          `Error in HTTP request: ${code}`,
         );
+        doCleanup();
         reject(err);
       });
 
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts 
b/packages/taler-wallet-core/src/operations/exchanges.ts
index 22be4102a..3f8126dba 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -137,7 +137,7 @@ const logger = new Logger("exchanges.ts");
 
 function getExchangeRequestTimeout(): Duration {
   return Duration.fromSpec({
-    seconds: 5,
+    seconds: 15,
   });
 }
 
@@ -653,6 +653,8 @@ async function downloadExchangeKeysInfo(
     cancellationToken,
   });
 
+  logger.info("got response to /keys request");
+
   // We must make sure to parse out the protocol version
   // before we validate the body.
   // Otherwise the parser might complain with a hard to understand
@@ -907,7 +909,7 @@ async function startUpdateExchangeEntry(
     newExchangeState: newExchangeState,
     oldExchangeState: oldExchangeState,
   });
-  ws.taskScheduler.restartShepherdTask(taskId);
+  await ws.taskScheduler.resetTaskRetries(taskId);
 }
 
 /**

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]