Skip to content

Commit cbbd500

Browse files
committed
Merge branch 'master' into push-to-client-sdks-oss-repos
2 parents b221017 + b13ff42 commit cbbd500

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

DelveClientSDK/DelveClient.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMess
7474
var tokenSource = new CancellationTokenSource();
7575
AsyncLocalKeepAliveCancellationTokenSource.Value = tokenSource;
7676
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+
**/
7788
var keep_alive_task = this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
7889
}
7990
}
@@ -341,10 +352,12 @@ public override async Task KeepClientAlive(HttpClient client_, String url, Cance
341352
ct.ThrowIfCancellationRequested();
342353
await Task.Delay(HttpClientFactory.KEEP_ALIVE_INTERVAL*1000);
343354
ct.ThrowIfCancellationRequested();
355+
344356
try {
345357
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);
348361
}
349362
}
350363
}
@@ -357,10 +370,19 @@ private async void KeepAliveProbe(HttpClient client_, CancellationToken ct)
357370
request.RequestUri = new System.Uri(this.BaseUrl, System.UriKind.RelativeOrAbsolute);
358371
request.Version = System.Net.HttpVersion.Version20;
359372

373+
var keepaliveFailureCnt = 0;
360374
try {
361375
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+
}
364386
}
365387
}
366388

0 commit comments

Comments
 (0)