Skip to content

Commit 31969fd

Browse files
committed
tried to fix client closing issue
1 parent 3fba7b2 commit 31969fd

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/SuperSocket.Client/EasyClient.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public abstract class EasyClient : IEasyClient
3737

3838
internal static readonly int DefaultSocketSenderPoolSize = 10;
3939

40+
private bool _continuousReceivingStarted = false;
41+
4042
protected EasyClient()
4143
: this(NullLogger.Instance)
4244
{
@@ -222,7 +224,9 @@ private void StartReceive()
222224
client.OnError("The receive task was cancelled.");
223225
return;
224226
}
225-
}, this, TaskContinuationOptions.OnlyOnFaulted);;
227+
}, this, TaskContinuationOptions.OnlyOnFaulted);
228+
229+
_continuousReceivingStarted = true;
226230
}
227231

228232
protected abstract Task StartReceiveAsync();
@@ -280,7 +284,17 @@ protected virtual async ValueTask SendAsync<TSendPackage>(IPackageEncoder<TSendP
280284

281285
public virtual async ValueTask CloseAsync()
282286
{
283-
await Connection.CloseAsync(CloseReason.LocalClosing);
287+
var closeTask = Connection.CloseAsync(CloseReason.LocalClosing);
288+
289+
if (_continuousReceivingStarted)
290+
{
291+
await closeTask;
292+
}
293+
else
294+
{
295+
await Task.WhenAll(closeTask.AsTask(), StartReceiveAsync());
296+
}
297+
284298
OnClosed(this, EventArgs.Empty);
285299
}
286300
}

0 commit comments

Comments
 (0)