Skip to content

Commit 95a787c

Browse files
committed
Fix/core timeout (#2753)
* added integration tests to make dotnetcore and desktop clr behave the same with regards to timoeouts and cancelled async requests * updated comments * fix cancellation of token should explicitly abort the request because the TPL methods that we convert to async are unaffected by a cancellation * ignore tests for now because they rely on fiddler rules artificially delaying the call * rename new-scripts back to scripts Conflicts: src/Elasticsearch.Net/Auditing/AuditEvent.cs src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs src/Elasticsearch.Net/Transport/Transport.cs src/Tests/tests.default.yaml
1 parent 6982aa7 commit 95a787c

File tree

18 files changed

+220
-33
lines changed

18 files changed

+220
-33
lines changed

build.bat

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SET FEED="elasticsearch-net"
3030
SET NEST_INTEGRATION_CLUSTER=
3131
SET NEST_TEST_FILTER=
3232
SET ELASTICSEARCH=
33+
SET INTEGRATE_CLR="one"
3334

3435
IF /I "%1"=="skiptests" (
3536
set SKIPTESTS="1"
@@ -69,6 +70,13 @@ IF /I "%TARGET%"=="release" (
6970
IF /I "%TARGET%"=="inc" (
7071
IF NOT [%2]==[] (set NEST_TEST_FILTER="%2")
7172
)
73+
IF /I "%TARGET%"=="integrate-all" (
74+
SET TARGET="integrate"
75+
SET INTEGRATE_CLR="all"
76+
IF NOT [%2]==[] (set ESVERSIONS="%2")
77+
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%~3")
78+
IF NOT [%4]==[] (set NEST_TEST_FILTER="%4")
79+
)
7280
IF /I "%TARGET%"=="integrate" (
7381
IF NOT [%2]==[] (set ESVERSIONS="%2")
7482
IF NOT [%3]==[] (set NEST_INTEGRATION_CLUSTER="%~3")
@@ -90,5 +98,5 @@ IF /I "%TARGET%"=="profile" (
9098
IF NOT [%3]==[] (set NEST_TEST_FILTER="%3")
9199
)
92100

93-
ECHO build.bat: target=%TARGET% skippakket=%SKIPPAKET% version=%VERSION% esversions=%ESVERSIONS% skiptests=%SKIPTESTS% apiKey=%APIKEYPROVIDED% feed=%FEED% escluster=%NEST_INTEGRATION_CLUSTER% testfilter=%NEST_TEST_FILTER% elasticsearch=%ELASTICSEARCH%
94-
"packages\build\FAKE\tools\Fake.exe" "build\\scripts\\Targets.fsx" "target=%TARGET%" "version=%VERSION%" "esversions=%ESVERSIONS%" "skiptests=%SKIPTESTS%" "apiKey=%APIKEY%" "feed=%FEED%" "escluster=%NEST_INTEGRATION_CLUSTER%" "testfilter=%NEST_TEST_FILTER%" "elasticsearch=%ELASTICSEARCH%"
101+
ECHO build.bat: target=%TARGET% skippakket=%SKIPPAKET% version=%VERSION% esversions=%ESVERSIONS% skiptests=%SKIPTESTS% apiKey=%APIKEYPROVIDED% feed=%FEED% escluster=%NEST_INTEGRATION_CLUSTER% testfilter=%NEST_TEST_FILTER% elasticsearch=%ELASTICSEARCH% integrateclr=%INTEGRATE_CLR%
102+
"packages\build\FAKE\tools\Fake.exe" "build\\scripts\\Targets.fsx" "target=%TARGET%" "version=%VERSION%" "esversions=%ESVERSIONS%" "skiptests=%SKIPTESTS%" "apiKey=%APIKEY%" "feed=%FEED%" "escluster=%NEST_INTEGRATION_CLUSTER%" "testfilter=%NEST_TEST_FILTER%" "elasticsearch=%ELASTICSEARCH%" "integrateclr=%INTEGRATE_CLR%"

build/scripts/Targets.fsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Target "Profile" <| fun _ ->
4949
let url = getBuildParam "elasticsearch"
5050
Profiler.IndexResults url
5151

52-
Target "Integrate" Tests.RunIntegrationTests
52+
Target "Integrate" <| fun _ ->
53+
let target = if getBuildParam "integrateclr" = "one" then Tests.MultiTarget.One else Tests.MultiTarget.All
54+
Tests.RunIntegrationTests target
5355

5456
Target "Benchmark" Benchmarker.Run
5557

build/scripts/Testing.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module Tests =
4444
setLocalEnvVars()
4545
dotnetTest All
4646

47-
let RunIntegrationTests() =
47+
let RunIntegrationTests target =
4848
setLocalEnvVars()
4949
let commaSeparatedEsVersions = getBuildParamOrDefault "esversions" ""
5050
let esVersions =
@@ -54,4 +54,4 @@ module Tests =
5454

5555
for esVersion in esVersions do
5656
setProcessEnvironVar "NEST_INTEGRATION_VERSION" esVersion
57-
dotnetTest One |> ignore
57+
dotnetTest target |> ignore

build/scripts/scripts.fsproj

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
1-
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
24
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{D6997ADC-E933-418E-831C-DE1A78897493}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>new_scripts</RootNamespace>
11+
<AssemblyName>new_scripts</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<Name>new_scripts</Name>
516
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<Tailcalls>false</Tailcalls>
22+
<OutputPath>bin\$(Configuration)\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<WarningLevel>3</WarningLevel>
25+
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<Tailcalls>true</Tailcalls>
31+
<OutputPath>bin\$(Configuration)\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<WarningLevel>3</WarningLevel>
34+
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="mscorlib" />
38+
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Numerics" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Data.Linq" />
46+
</ItemGroup>
647
<ItemGroup>
748
<None Include="Projects.fsx" />
849
<None Include="Paths.fsx" />
@@ -18,16 +59,27 @@
1859
<None Include="Documentation.fsx" />
1960
<None Include="Targets.fsx" />
2061
</ItemGroup>
21-
<ItemGroup>
22-
<Reference Include="mscorlib" />
23-
<Reference Include="System" />
24-
<Reference Include="System.Core" />
25-
<Reference Include="System.Data" />
26-
<Reference Include="System.Data.Linq" />
27-
<Reference Include="System.Numerics" />
28-
<Reference Include="System.Drawing" />
29-
<Reference Include="System.Windows.Forms" />
30-
<PackageReference Include="FSharp.Core" Version="4.1.*" />
31-
</ItemGroup>
32-
<Import Project="..\..\.paket\Paket.Restore.targets" />
33-
</Project>
62+
<PropertyGroup>
63+
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
64+
</PropertyGroup>
65+
<Choose>
66+
<When Condition="'$(VisualStudioVersion)' == '11.0'">
67+
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
68+
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
69+
</PropertyGroup>
70+
</When>
71+
<Otherwise>
72+
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
73+
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
74+
</PropertyGroup>
75+
</Otherwise>
76+
</Choose>
77+
<Import Project="$(FSharpTargetsPath)" />
78+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
79+
Other similar extension points exist, see Microsoft.Common.targets.
80+
<Target Name="BeforeBuild">
81+
</Target>
82+
<Target Name="AfterBuild">
83+
</Target>
84+
-->
85+
</Project>

src/Elasticsearch.Net/Auditing/AuditEvent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public enum AuditEvent
1919
MaxTimeoutReached,
2020
MaxRetriesReached,
2121
BadRequest
22+
CancellationRequested,
2223
}
2324
}

src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public virtual ElasticsearchResponse<TReturn> Request<TReturn>(RequestData reque
7676
if (response.Content != null)
7777
builder.Stream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
7878
}
79+
catch (TaskCanceledException e)
80+
{
81+
builder.Exception = e;
82+
}
7983
catch (HttpRequestException e)
8084
{
8185
builder.Exception = e;
@@ -98,6 +102,10 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
98102
if (response.Content != null)
99103
builder.Stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
100104
}
105+
catch (TaskCanceledException e)
106+
{
107+
builder.Exception = e;
108+
}
101109
catch (HttpRequestException e)
102110
{
103111
builder.Exception = e;

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
191191
try
192192
{
193193
var request = this.CreateHttpWebRequest(requestData);
194+
cancellationToken.Register(()=>request.Abort());
194195
var data = requestData.PostData;
195196

196197
if (data != null)
@@ -216,6 +217,7 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
216217

217218
var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null);
218219
RegisterApmTaskTimeout(apmGetResponseTask, request, requestData);
220+
219221
var response = (HttpWebResponse)(await apmGetResponseTask.ConfigureAwait(false));
220222
builder.StatusCode = (int)response.StatusCode;
221223
builder.Stream = response.GetResponseStream();

src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ public interface IRequestPipeline : IDisposable
4545

4646
void BadResponse<TReturn>(ref ElasticsearchResponse<TReturn> response, RequestData requestData, List<PipelineException> seenExceptions)
4747
where TReturn : class;
48+
49+
void AuditCancellationRequested();
4850
}
4951
}

src/Elasticsearch.Net/Transport/Pipeline/PipelineException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static string GetMessage(PipelineFailure failure)
3737
switch(failure)
3838
{
3939
case PipelineFailure.BadRequest:
40-
return "An error occurred trying to write the request datato the specified node.";
40+
return "An error occurred trying to write the request data to the specified node.";
4141
case PipelineFailure.BadResponse:
4242
return "An error occurred trying to read the response from the specified node.";
4343
case PipelineFailure.BadAuthentication:

src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public bool IsTakingTooLong
113113

114114
private Auditable Audit(AuditEvent type) => new Auditable(type, this.AuditTrail, this._dateTimeProvider);
115115

116+
public void AuditCancellationRequested() => Audit(CancellationRequested).Dispose();
117+
116118
public void MarkDead(Node node)
117119
{
118120
var deadUntil = this._dateTimeProvider.DeadTime(node.FailedAttempts, this._settings.DeadTimeout, this._settings.MaxDeadTimeout);

0 commit comments

Comments
 (0)