@@ -74,6 +74,17 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess
74
74
var tokenSource = new CancellationTokenSource ( ) ;
75
75
AsyncLocalKeepAliveCancellationTokenSource . Value = tokenSource ;
76
76
CancellationToken ct = tokenSource . Token ;
77
+
78
+ /**
79
+ * TODO: currently we swallo exceptions in KeepClientAlive.
80
+ * If we want to throw, then we need to change this to asynchronously handle the throw
81
+ * e.g.
82
+ * try {
83
+ await this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
84
+ } catch (Exception e) {
85
+ // Handle here
86
+ }
87
+ **/
77
88
var keep_alive_task = this . KeepClientAlive ( client , url , ct ) . ConfigureAwait ( false ) ;
78
89
}
79
90
}
@@ -341,10 +352,12 @@ public override async Task KeepClientAlive(HttpClient client_, String url, Cance
341
352
ct . ThrowIfCancellationRequested ( ) ;
342
353
await Task . Delay ( HttpClientFactory . KEEP_ALIVE_INTERVAL * 1000 ) ;
343
354
ct . ThrowIfCancellationRequested ( ) ;
355
+
344
356
try {
345
357
await Task . Run ( ( ) => this . KeepAliveProbe ( client_ , ct ) ) ;
346
- } catch {
347
- //ignore the error
358
+ } catch ( Exception e ) {
359
+ // ignore. But I think we might want to throw?
360
+ Logger . Error ( "KeepAliveProbe failed with exception: " + e . Message ) ;
348
361
}
349
362
}
350
363
}
@@ -357,10 +370,19 @@ private async void KeepAliveProbe(HttpClient client_, CancellationToken ct)
357
370
request . RequestUri = new System . Uri ( this . BaseUrl , System . UriKind . RelativeOrAbsolute ) ;
358
371
request . Version = System . Net . HttpVersion . Version20 ;
359
372
373
+ var keepaliveFailureCnt = 0 ;
360
374
try {
361
375
await client_ . SendAsync ( request , System . Net . Http . HttpCompletionOption . ResponseHeadersRead , ct ) . ConfigureAwait ( false ) ;
362
- } catch {
363
- //ignore the error
376
+ } catch ( Exception e ) {
377
+ keepaliveFailureCnt ++ ;
378
+ // KEEP_ALIVE_RETRIES may be too big here (16) for the interval of 3 minutes
379
+ if ( keepaliveFailureCnt < HttpClientFactory . KEEP_ALIVE_RETRIES ) {
380
+ Logger . Warning ( "KeepAliveProbe failed to send request: " + e . Message ) ;
381
+ } else {
382
+ Logger . Error ( "KeepAliveProbe failed to send request: " + e . Message ) ;
383
+ Logger . Error ( "KeepAliveProbe retry exceeded max. Throwing" ) ;
384
+ throw e ;
385
+ }
364
386
}
365
387
}
366
388
0 commit comments