Skip to content

Commit 909a417

Browse files
committed
Fixed Pool Reset Issue
1 parent d3d9f33 commit 909a417

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

src/HotChocolate/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<PackageIcon>hotchocolate-signet.png</PackageIcon>
55
</PropertyGroup>
66
<PropertyGroup>
7-
<NitroVersion>28.0.14</NitroVersion>
7+
<NitroVersion>29.0.0-insider.22</NitroVersion>
88
</PropertyGroup>
99
</Project>

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Results/ResultDataBatch.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace HotChocolate.Fusion.Execution;
1010
private readonly int _maxAllowedCapacity;
1111
private readonly T[] _items;
1212
private int _next = -1;
13+
#pragma warning disable IDE0052 // Remove unread private members
14+
private readonly int _inst;
15+
#pragma warning restore IDE0052 // Remove unread private members
1316

1417
public ResultDataBatch(int batchSize, int defaultCapacity = 8, int maxAllowedCapacity = 16)
1518
{
@@ -26,6 +29,8 @@ public ResultDataBatch(int batchSize, int defaultCapacity = 8, int maxAllowedCap
2629
{
2730
_items[i] = CreateItem();
2831
}
32+
33+
_inst = Interlocked.Increment(ref InstanceCounter.Counter);
2934
}
3035

3136
private T CreateItem()
@@ -62,7 +67,7 @@ public void Reset()
6267
return;
6368
}
6469

65-
var usedItem = _next < _items.Length ? _next : _items.Length;
70+
var usedItem = _next < _items.Length ? _next + 1 : _items.Length;
6671
ref var item = ref MemoryMarshal.GetReference(_items.AsSpan());
6772
ref var end = ref Unsafe.Add(ref item, usedItem);
6873

@@ -78,3 +83,8 @@ public void Reset()
7883
_next = -1;
7984
}
8085
}
86+
87+
public static class InstanceCounter
88+
{
89+
public static int Counter;
90+
}

src/HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/BookStoreTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,62 @@ public async Task Fetch_Book_From_SourceSchema1()
4444
response.MatchSnapshot();
4545
}
4646

47+
[Fact]
48+
public async Task Fetch_Book_From_SourceSchema1_Two_Requests()
49+
{
50+
// arrange
51+
using var server1 = CreateSourceSchema(
52+
"A",
53+
b => b.AddQueryType<SourceSchema1.Query>());
54+
55+
using var server2 = CreateSourceSchema(
56+
"B",
57+
b => b.AddQueryType<SourceSchema2.Query>());
58+
59+
// act
60+
using var gateway = await CreateCompositeSchemaAsync(
61+
[
62+
("A", server1),
63+
("B", server2),
64+
]);
65+
66+
// assert
67+
using var client = GraphQLHttpClient.Create(gateway.CreateClient());
68+
69+
using var result1 = await client.PostAsync(
70+
"""
71+
{
72+
bookById(id: 1) {
73+
id
74+
title
75+
}
76+
}
77+
""",
78+
new Uri("http://localhost:5000/graphql"));
79+
80+
using (var response = await result1.ReadAsResultAsync())
81+
{
82+
response.MatchSnapshot();
83+
}
84+
85+
using var result2 = await client.PostAsync(
86+
"""
87+
{
88+
bookById(id: 1) {
89+
id
90+
title
91+
}
92+
}
93+
""",
94+
new Uri("http://localhost:5000/graphql"));
95+
96+
// act
97+
using (var response = await result2.ReadAsResultAsync())
98+
{
99+
response.MatchSnapshot();
100+
}
101+
}
102+
47103
[Fact]
48104
public async Task Fetch_Book_From_SourceSchema1_And_Author_From_SourceSchema2()
49105
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"data": {
3+
"bookById": {
4+
"id": 1,
5+
"title": "C# in Depth"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)