Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented RSC15f and RTN17e and improved fallback handling #385

Merged
merged 15 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/AblyRealtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal AblyRealtime(ClientOptions options, Func<ClientOptions, AblyRest> creat
Channels = new RealtimeChannels(this, Connection);
RestClient.AblyAuth.OnAuthUpdated = ConnectionManager.OnAuthUpdated;

State = new RealtimeState(options.FallbackHosts?.Shuffle().ToList());
State = new RealtimeState(options.FallbackHosts?.Shuffle().ToList(), options.NowFunc);

Workflow = new RealtimeWorkflow(this, Logger);
Workflow.Start();
Expand Down
20 changes: 13 additions & 7 deletions src/IO.Ably.Shared/AblyRest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public AblyRest(ClientOptions clientOptions)

internal MessageHandler MessageHandler { get; private set; }

internal string CustomHost
{
get => HttpClient.CustomHost;
set => HttpClient.CustomHost = value;
}
internal void SetRealtimeFallbackHost(string host)
=> HttpClient.RealtimeConnectedFallbackHost = host;

internal void ClearRealtimeFallbackHost()
=> HttpClient.RealtimeConnectedFallbackHost = null;

internal AblyAuth AblyAuth { get; private set; }

Expand Down Expand Up @@ -364,8 +364,14 @@ public async Task<bool> CanConnectToAbly()
try
{
var request = new AblyRequest(Defaults.InternetCheckUrl, HttpMethod.Get);
var response = await ExecuteHttpRequest(request);
return response.TextResponse == Defaults.InternetCheckOkMessage;
var response = await ExecuteHttpRequest(request).TimeoutAfter(Defaults.MaxHttpOpenTimeout, AblyResponse.EmptyResponse);
var success = response.TextResponse == Defaults.InternetCheckOkMessage;
if (success == false)
{
Logger.Warning("Cannot get a valid internet connection. Response: " + response.TextResponse);
}

return success;
}
catch (Exception ex)
{
Expand Down
19 changes: 13 additions & 6 deletions src/IO.Ably.Shared/ClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,37 +219,44 @@ public bool UseBinaryProtocol
/// Number of seconds before the library will retry after reaching Suspended state.
/// Default: 30s.
/// </summary>
public TimeSpan SuspendedRetryTimeout { get; set; } = TimeSpan.FromSeconds(30);
public TimeSpan SuspendedRetryTimeout { get; set; } = Defaults.SuspendedRetryTimeout;

/// <summary>
/// Number of seconds before a channel will try to reattach itself after becoming suspended.
/// Default: 15s.
/// </summary>
public TimeSpan ChannelRetryTimeout { get; set; } = TimeSpan.FromSeconds(15);
public TimeSpan ChannelRetryTimeout { get; set; } = Defaults.ChannelRetryTimeout;

/// <summary>
/// Timeout for opening an http request.
/// Default: 4s.
/// </summary>
public TimeSpan HttpOpenTimeout { get; set; } = TimeSpan.FromSeconds(4);
public TimeSpan HttpOpenTimeout { get; set; } = Defaults.MaxHttpOpenTimeout;

/// <summary>
/// Timeout for completing an http request.
/// Default: 10s.
/// </summary>
public TimeSpan HttpRequestTimeout { get; set; } = TimeSpan.FromSeconds(10);
public TimeSpan HttpRequestTimeout { get; set; } = Defaults.MaxHttpRequestTimeout;

/// <summary>
/// After a failed request to the default endpoint, followed by a successful request to a fallback endpoint),
/// the period in milliseconds before HTTP requests are retried against the default endpoint.
/// Default: 10 minutes.
/// </summary>
public TimeSpan FallbackRetryTimeout { get; set; } = Defaults.FallbackRetryTimeout;

/// <summary>
/// Maximum number of Http retries the library will attempt.
/// Default: 3.
/// </summary>
public int HttpMaxRetryCount { get; set; } = 3;
public int HttpMaxRetryCount { get; set; } = Defaults.HttpMaxRetryCount;

/// <summary>
/// Duration for which the library will retry an http request.
/// Default: 15s.
/// </summary>
public TimeSpan HttpMaxRetryDuration { get; set; } = TimeSpan.FromSeconds(15);
public TimeSpan HttpMaxRetryDuration { get; set; } = Defaults.HttpMaxRetryDuration;

/// <summary>
/// Provides Channels Setting for all Channels created. For more information see <see cref="ChannelOptions"/>.
Expand Down
7 changes: 7 additions & 0 deletions src/IO.Ably.Shared/Defaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ public static string LibraryVersion

// Buffer in seconds before a token is considered unusable
public const int TokenExpireBufferInSeconds = 15;
public const int HttpMaxRetryCount = 3;
public static readonly TimeSpan ChannelRetryTimeout = TimeSpan.FromSeconds(15);
public static readonly TimeSpan HttpMaxRetryDuration = TimeSpan.FromSeconds(15);
public static readonly TimeSpan MaxHttpRequestTimeout = TimeSpan.FromSeconds(15);
public static readonly TimeSpan MaxHttpOpenTimeout = TimeSpan.FromSeconds(4);
public static readonly TimeSpan DefaultRealtimeTimeout = TimeSpan.FromSeconds(10);
public static readonly TimeSpan DisconnectedRetryTimeout = TimeSpan.FromSeconds(15);
public static readonly TimeSpan SuspendedRetryTimeout = TimeSpan.FromSeconds(30);
public static readonly TimeSpan ConnectionStateTtl = TimeSpan.FromSeconds(60);
public static readonly TimeSpan FallbackRetryTimeout = TimeSpan.FromMinutes(10); // https://docs.ably.io/client-lib-development-guide/features/#TO3l10

public static readonly ITransportFactory WebSocketTransportFactory = IoC.TransportFactory;

Expand Down
Loading