Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #133 from nic-burgers-arup/nic/unresponsive-server
Browse files Browse the repository at this point in the history
Nic/unresponsive server
  • Loading branch information
teocomi committed Sep 10, 2019
2 parents 666014c + fa869a3 commit e0670aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
19 changes: 16 additions & 3 deletions ApiClient/SpeckleApiClientApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -394,7 +395,11 @@ public async System.Threading.Tasks.Task<ResponseUser> UserGetAsync( System.Thre
}
}
}
finally
catch (TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle Server", (int)HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( client_ != null )
client_.Dispose();
Expand Down Expand Up @@ -2391,7 +2396,11 @@ public async System.Threading.Tasks.Task<ResponseStream> StreamGetAsync( string
}
}
}
finally
catch (TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle Server", (int)HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( client_ != null )
client_.Dispose();
Expand Down Expand Up @@ -2688,6 +2697,10 @@ public async System.Threading.Tasks.Task<ResponseObject> StreamGetObjectsAsync(

return default( ResponseObject );
}
catch (TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle server", (int) HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( response_ != null )
Expand Down Expand Up @@ -3412,7 +3425,7 @@ public async System.Threading.Tasks.Task<ResponseObject> ObjectGetBulkAsync( str
if ( query != null ) urlBuilder_.Append( query );


var client_ = GetHttpClient();
var client_ = GetHttpClient(defaultBulkTimeoutMilliseconds);
try
{
using ( var request_ = new System.Net.Http.HttpRequestMessage() )
Expand Down
4 changes: 4 additions & 0 deletions ApiClient/SpeckleApiClientExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public partial class SpeckleApiClient : ISerializable

Timer IsReady, WsReconnecter;

//Default timeouts, pending further discussion
private double defaultTimeoutMilliseconds = 3000;
private double defaultBulkTimeoutMilliseconds = 60000;

private Dictionary<string, SpeckleObject> ObjectCache = new Dictionary<string, SpeckleObject>();


Expand Down
13 changes: 9 additions & 4 deletions ApiClient/SpeckleApiClientHead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ partial void PrepareRequest( HttpClient client, HttpRequestMessage request, stri
request.Content = new GzipContent( request.Content );
}

private HttpClient GetHttpClient( )
private HttpClient GetHttpClient(double timeoutMillisecondsOverride = 0)
{
var handler = new HttpClientHandler();
handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
return new HttpClient( handler, true );
var handler = new HttpClientHandler
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
};
return new HttpClient(handler, true)
{
Timeout = TimeSpan.FromMilliseconds(timeoutMillisecondsOverride == 0 ? defaultTimeoutMilliseconds : timeoutMillisecondsOverride)
};
}
}
}

0 comments on commit e0670aa

Please sign in to comment.