Attempt 3 for fixing SSL/TLS bug
This commit is contained in:
@@ -44,11 +44,25 @@ namespace Discord.Net.API
|
||||
}
|
||||
private async Task<string> Send(RestRequest request, CancellationToken cancelToken)
|
||||
{
|
||||
var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false);
|
||||
int statusCode = (int)response.StatusCode;
|
||||
if (statusCode < 200 || statusCode >= 300) //2xx = Success
|
||||
throw new HttpException(response.StatusCode);
|
||||
return response.Content;
|
||||
bool hasRetried = false;
|
||||
while (true)
|
||||
{
|
||||
var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false);
|
||||
int statusCode = (int)response.StatusCode;
|
||||
if (statusCode == 0) //Internal Error
|
||||
{
|
||||
if (!hasRetried)
|
||||
{
|
||||
//SSL/TTS Error seems to work if we immediately retry
|
||||
hasRetried = true;
|
||||
continue;
|
||||
}
|
||||
throw response.ErrorException;
|
||||
}
|
||||
if (statusCode < 200 || statusCode >= 300) //2xx = Success
|
||||
throw new HttpException(response.StatusCode);
|
||||
return response.Content;
|
||||
}
|
||||
}
|
||||
|
||||
private Method GetMethod(HttpMethod method)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
@@ -21,7 +20,6 @@ namespace Discord.Net.API
|
||||
private readonly IRestEngine _engine;
|
||||
private readonly LogMessageSeverity _logLevel;
|
||||
private CancellationToken _cancelToken;
|
||||
private ServicePoint _servicePoint;
|
||||
|
||||
public RestClient(LogMessageSeverity logLevel)
|
||||
{
|
||||
@@ -111,8 +109,6 @@ namespace Discord.Net.API
|
||||
stopwatch = Stopwatch.StartNew();
|
||||
|
||||
string responseJson = await _engine.Send(method, path, requestJson, _cancelToken).ConfigureAwait(false);
|
||||
if (_servicePoint == null)
|
||||
ConfigureServicePoint();
|
||||
|
||||
#if TEST_RESPONSES
|
||||
if (!hasResponse && !string.IsNullOrEmpty(responseJson))
|
||||
@@ -152,8 +148,6 @@ namespace Discord.Net.API
|
||||
stopwatch = Stopwatch.StartNew();
|
||||
|
||||
string responseJson = await _engine.SendFile(method, path, filePath, _cancelToken).ConfigureAwait(false);
|
||||
if (_servicePoint == null)
|
||||
ConfigureServicePoint();
|
||||
|
||||
#if TEST_RESPONSES
|
||||
if (!hasResponse && !string.IsNullOrEmpty(responseJson))
|
||||
@@ -192,14 +186,5 @@ namespace Discord.Net.API
|
||||
|
||||
internal void SetToken(string token) => _engine.SetToken(token);
|
||||
internal void SetCancelToken(CancellationToken token) => _cancelToken = token;
|
||||
|
||||
private void ConfigureServicePoint()
|
||||
{
|
||||
_servicePoint = ServicePointManager.FindServicePoint(new Uri(Endpoints.BaseApi));
|
||||
_servicePoint.Expect100Continue = true;
|
||||
_servicePoint.UseNagleAlgorithm = false;
|
||||
_servicePoint.MaxIdleTime = int.MaxValue;
|
||||
_servicePoint.ConnectionLeaseTimeout = int.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user