Skip to content

Commit

Permalink
fix(dui): do not break the get streams loop if one server times out (#…
Browse files Browse the repository at this point in the history
…2860)

* fix(dui): do not break the get streams loop if one server times out

* add configurable timeout to http client factory

* configurettimeout value overrides

* fix(dui): Fixed regression with cancellation of searches

---------

Co-authored-by: Gergő Jedlicska <[email protected]>
Co-authored-by: Jedd Morgan <[email protected]>
  • Loading branch information
3 people authored Aug 25, 2023
1 parent 562080c commit 2c3023b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Core/Core/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Client(Account account)

Account = account;

HttpClient = Http.GetHttpProxyClient();
HttpClient = Http.GetHttpProxyClient(null, TimeSpan.FromSeconds(30));
Http.AddAuthHeader(HttpClient, account.token);

HttpClient.DefaultRequestHeaders.Add("apollographql-client-name", Setup.HostApplication);
Expand Down
6 changes: 4 additions & 2 deletions Core/Core/Helpers/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ public static async Task<bool> HttpPing(string address)
}
}

public static HttpClient GetHttpProxyClient(SpeckleHttpClientHandler? handler = null)
public static HttpClient GetHttpProxyClient(SpeckleHttpClientHandler? handler = null, TimeSpan? timeout = null)
{
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;

return new HttpClient(handler ?? new SpeckleHttpClientHandler());
var client = new HttpClient(handler ?? new SpeckleHttpClientHandler());
client.Timeout = timeout ?? TimeSpan.FromSeconds(100);
return client;
}

public static bool CanAddAuth(string? authToken, out string? bearerHeader)
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Transports/ServerUtils/ServerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ServerApi(string baseUri, string? authorizationToken, string blobStorageF
);

_client.BaseAddress = new Uri(baseUri);
_client.Timeout = new TimeSpan(0, 0, timeoutSeconds);
_client.Timeout = TimeSpan.FromSeconds(timeoutSeconds);

Http.AddAuthHeader(_client, authorizationToken);
}
Expand Down
26 changes: 14 additions & 12 deletions DesktopUI2/DesktopUI2/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ private async Task GetStreams()
}
catch (OperationCanceledException)
{
return;
continue;
}
catch (Exception e)
catch (Exception ex)
{
if (e.InnerException is TaskCanceledException)
if (ex.InnerException is TaskCanceledException)
return;

SpeckleLog.Logger.Error(e, "Could not fetch streams");
SpeckleLog.Logger.Error(ex, "Could not fetch streams");

Dispatcher.UIThread.Post(
() =>
Expand Down Expand Up @@ -731,15 +731,17 @@ private async void OpenStreamCommand(object streamAccountWrapper)
if (await CheckIsOffline().ConfigureAwait(true))
return;



if (streamAccountWrapper != null)
{
var streamState = new StreamState(streamAccountWrapper as StreamAccountWrapper);

if (!await streamState.Client.IsStreamAccessible(streamState.StreamId).ConfigureAwait(true))
{
Dialogs.ShowDialog("Stream not found", "Please ensure the stream exists and that you have access to it.", DialogIconKind.Error);
Dialogs.ShowDialog(
"Stream not found",
"Please ensure the stream exists and that you have access to it.",
DialogIconKind.Error
);
return;
}

Expand All @@ -755,16 +757,17 @@ private async void OpenSavedStreamCommand(object streamViewModel)
if (await CheckIsOffline().ConfigureAwait(true))
return;



if (streamViewModel != null && streamViewModel is StreamViewModel svm && !svm.NoAccess)
{

try
{
if (!await svm.Client.IsStreamAccessible(svm.Stream.id).ConfigureAwait(true))
{
Dialogs.ShowDialog("Stream not found", "Please ensure the stream exists and that you have access to it.", DialogIconKind.Error);
Dialogs.ShowDialog(
"Stream not found",
"Please ensure the stream exists and that you have access to it.",
DialogIconKind.Error
);
return;
}

Expand All @@ -778,7 +781,6 @@ private async void OpenSavedStreamCommand(object streamViewModel)
SpeckleLog.Logger.Error(ex, "Failed to open saved stream {exceptionMessage}", ex.Message);
}
}

}

public void ToggleDarkThemeCommand()
Expand Down

0 comments on commit 2c3023b

Please sign in to comment.