Skip to content

Commit 07d2c41

Browse files
authored
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
1 parent 8fce6ad commit 07d2c41

File tree

18 files changed

+219
-32
lines changed

18 files changed

+219
-32
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
@@ -20,5 +20,6 @@ public enum AuditEvent
2020
MaxRetriesReached,
2121
BadRequest,
2222
NoNodesAttempted,
23+
CancellationRequested,
2324
}
2425
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public virtual ElasticsearchResponse<TReturn> Request<TReturn>(RequestData reque
7777
if (response.Content != null)
7878
builder.Stream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
7979
}
80+
catch (TaskCanceledException e)
81+
{
82+
builder.Exception = e;
83+
}
8084
catch (HttpRequestException e)
8185
{
8286
builder.Exception = e;
@@ -102,6 +106,10 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
102106
if (response.Content != null)
103107
builder.Stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
104108
}
109+
catch (TaskCanceledException e)
110+
{
111+
builder.Exception = e;
112+
}
105113
catch (HttpRequestException e)
106114
{
107115
builder.Exception = e;

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
195195
try
196196
{
197197
var request = this.CreateHttpWebRequest(requestData);
198+
cancellationToken.Register(()=>request.Abort());
198199
var data = requestData.PostData;
199200

200201
if (data != null)
@@ -220,6 +221,7 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
220221

221222
var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null);
222223
RegisterApmTaskTimeout(apmGetResponseTask, request, requestData);
224+
223225
var response = (HttpWebResponse)(await apmGetResponseTask.ConfigureAwait(false));
224226
builder.StatusCode = (int)response.StatusCode;
225227
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
@@ -47,5 +47,7 @@ void BadResponse<TReturn>(ref ElasticsearchResponse<TReturn> response, RequestDa
4747
where TReturn : class;
4848

4949
void ThrowNoNodesAttempted(RequestData requestData, List<PipelineException> seenExceptions);
50+
51+
void AuditCancellationRequested();
5052
}
5153
}

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
@@ -123,6 +123,8 @@ public void ThrowNoNodesAttempted(RequestData requestData, List<PipelineExceptio
123123
};
124124
}
125125

126+
public void AuditCancellationRequested() => Audit(CancellationRequested).Dispose();
127+
126128
public void MarkDead(Node node)
127129
{
128130
var deadUntil = this._dateTimeProvider.DeadTime(node.FailedAttempts, this._settings.DeadTimeout, this._settings.MaxDeadTimeout);

0 commit comments

Comments
 (0)