Skip to content

Commit 5c398f7

Browse files
requested fixes
1 parent 4be0d2c commit 5c398f7

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

src/tarantool.client/Box.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public Box(ClientOptions options)
1717
_clientOptions = options;
1818
TarantoolConvertersRegistrator.Register(options.MsgPackContext);
1919

20-
_logicalConnection = new LogicalConnectionWrapper(options);
20+
_logicalConnection = new LogicalConnectionManager(options);
2121
}
2222

2323
public async Task Connect()

src/tarantool.client/LogicalConnection.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@ public LogicalConnection(ClientOptions options, RequestIdCounter requestIdCounte
4242

4343
public void Dispose()
4444
{
45-
lock (this)
45+
if (_disposed)
4646
{
47-
if (_disposed)
48-
{
49-
return;
50-
}
47+
return;
48+
}
5149

52-
_disposed = true;
50+
_disposed = true;
5351

54-
_responseReader.Dispose();
55-
_physicalConnection.Dispose();
56-
}
52+
_responseReader.Dispose();
53+
_physicalConnection.Dispose();
5754
}
5855

5956
public async Task Connect()
@@ -87,7 +84,6 @@ public bool IsConnected()
8784

8885
if (!_responseReader.IsConnected() || !_physicalConnection.IsConnected())
8986
{
90-
Dispose();
9187
return false;
9288
}
9389

@@ -155,11 +151,14 @@ private async Task<TResponse> SendRequestImpl<TRequest, TResponse>(TRequest requ
155151

156152
try
157153
{
158-
_logWriter?.WriteLine($"Begin sending request header buffer, requestId: {requestId}, code: {request.Code}, length: {headerBuffer.Length}");
159-
_physicalConnection.Write(headerBuffer, 0, Constants.PacketSizeBufferSize + (int)headerLength);
154+
lock (_physicalConnection)
155+
{
156+
_logWriter?.WriteLine($"Begin sending request header buffer, requestId: {requestId}, code: {request.Code}, length: {headerBuffer.Length}");
157+
_physicalConnection.Write(headerBuffer, 0, Constants.PacketSizeBufferSize + (int)headerLength);
160158

161-
_logWriter?.WriteLine($"Begin sending request body buffer, length: {bodyBuffer.Length}");
162-
_physicalConnection.Write(bodyBuffer, 0, bodyBuffer.Length);
159+
_logWriter?.WriteLine($"Begin sending request body buffer, length: {bodyBuffer.Length}");
160+
_physicalConnection.Write(bodyBuffer, 0, bodyBuffer.Length);
161+
}
163162
}
164163
catch (Exception ex)
165164
{

src/tarantool.client/LogicalConnectionWrapper.cs renamed to src/tarantool.client/LogicalConnectionManager.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using ProGaudi.Tarantool.Client.Model.Requests;
43
using ProGaudi.Tarantool.Client.Model.Responses;
54

@@ -10,7 +9,7 @@ namespace ProGaudi.Tarantool.Client
109
using ProGaudi.Tarantool.Client.Model;
1110
using ProGaudi.Tarantool.Client.Utils;
1211

13-
public class LogicalConnectionWrapper : ILogicalConnection
12+
public class LogicalConnectionManager : ILogicalConnection
1413
{
1514
private readonly ClientOptions _clientOptions;
1615

@@ -24,7 +23,7 @@ public class LogicalConnectionWrapper : ILogicalConnection
2423

2524
private const int connectionTimeout = 1000;
2625

27-
public LogicalConnectionWrapper(ClientOptions options)
26+
public LogicalConnectionManager(ClientOptions options)
2827
{
2928
_clientOptions = options;
3029
}
@@ -36,7 +35,7 @@ public void Dispose()
3635

3736
public async Task Connect()
3837
{
39-
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionWrapper)}: Connecting...");
38+
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Connecting...");
4039

4140
_connected.Reset();
4241

@@ -46,7 +45,7 @@ public async Task Connect()
4645

4746
_connected.Set();
4847

49-
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionWrapper)}: Connected...");
48+
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Connected...");
5049
}
5150

5251
public bool IsConnected()
@@ -61,11 +60,11 @@ private async Task EnsureConnection()
6160
return;
6261
}
6362

64-
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionWrapper)}: Connection lost, wait for reconnect...");
63+
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Connection lost, wait for reconnect...");
6564

6665
if (!_reconnectAvailable.WaitOne(connectionTimeout))
6766
{
68-
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionWrapper)}: Failed to get lock for reconnect");
67+
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Failed to get lock for reconnect");
6968
throw ExceptionHelper.NotConnected();
7069
}
7170

@@ -76,7 +75,7 @@ private async Task EnsureConnection()
7675
await Connect();
7776
}
7877

79-
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionWrapper)}: Connection reacquired");
78+
_clientOptions.LogWriter?.WriteLine($"{nameof(LogicalConnectionManager)}: Connection reacquired");
8079
}
8180
finally
8281
{

src/tarantool.client/NetworkStreamPhysicalConnection.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ internal class NetworkStreamPhysicalConnection : INetworkStreamPhysicalConnectio
2424

2525
public void Dispose()
2626
{
27-
lock (this)
27+
if (_disposed)
2828
{
29-
if (_disposed)
30-
{
31-
return;
32-
}
29+
return;
30+
}
3331

34-
_disposed = true;
32+
_disposed = true;
3533

36-
_stream?.Dispose();
37-
_socket?.Dispose();
38-
}
34+
_stream?.Dispose();
35+
_socket?.Dispose();
3936
}
4037

4138
public async Task Connect(ClientOptions options)
@@ -122,6 +119,11 @@ private static Task ConnectAsync(Socket socket, string host, int port)
122119

123120
public bool IsConnected()
124121
{
122+
if (_disposed)
123+
{
124+
return false;
125+
}
126+
125127
try
126128
{
127129
return !(_socket.Poll(1, SelectMode.SelectRead) && _socket.Available == 0);

0 commit comments

Comments
 (0)