Skip to content

Commit ad05fde

Browse files
authored
chore: remove MaxReceiveMessageSize limit from gRPC client (#571)
Removes the max size of messages that can be received by the .NET gRPC client. This prevents errors when the client receives large values from the library.
1 parent 32cd9f0 commit ad05fde

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-grpc-impl/GrpcLibSpanner.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public static GrpcChannel ForUnixSocket(string fileName)
4545
throw;
4646
}
4747
}
48-
}
48+
},
49+
MaxReceiveMessageSize = null,
4950
});
5051
}
5152

@@ -56,7 +57,8 @@ public static GrpcChannel ForTcpSocket(string address)
5657
HttpHandler = new SocketsHttpHandler
5758
{
5859
EnableMultipleHttp2Connections = true,
59-
}
60+
},
61+
MaxReceiveMessageSize = null,
6062
});
6163
}
6264

spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-tests/RowsTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ public void TestRandomResults([Values] LibType libType)
7777
var request = Fixture.SpannerMock.Requests.OfType<ExecuteSqlRequest>().First();
7878
Assert.That(request.Transaction?.SingleUse?.ReadOnly?.HasStrong ?? false);
7979
}
80+
81+
[Test]
82+
public void TestLargeStringValue([Values] LibType libType)
83+
{
84+
const string sql = "select large_value from my_table";
85+
var value = TestUtils.GenerateRandomString(10_000_000);
86+
Fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateSingleColumnResultSet(
87+
new Spanner.V1.Type{Code = TypeCode.String}, "large_value", value));
88+
89+
using var pool = Pool.Create(SpannerLibDictionary[libType], ConnectionString);
90+
using var connection = pool.CreateConnection();
91+
using var rows = connection.Execute(new ExecuteSqlRequest { Sql = sql });
92+
var numRows = 0;
93+
while (rows.Next() is { } row)
94+
{
95+
numRows++;
96+
Assert.That(row.Values.Count, Is.EqualTo(1));
97+
Assert.That(row.Values[0].HasStringValue);
98+
Assert.That(row.Values[0].StringValue, Is.EqualTo(value));
99+
}
100+
Assert.That(numRows, Is.EqualTo(1));
101+
}
80102

81103
[Test]
82104
public void TestStopHalfway([Values] LibType libType)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Google.Cloud.SpannerLib.Tests;
2+
3+
public static class TestUtils
4+
{
5+
private const string Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
6+
7+
public static string GenerateRandomString(int length)
8+
{
9+
return new string(Enumerable.Repeat(Chars, length)
10+
.Select(s => s[Random.Shared.Next(s.Length)]).ToArray());
11+
}
12+
}

0 commit comments

Comments
 (0)