Skip to content

Commit

Permalink
Added try/catch inside send heartbeat to avoid channel closed exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Noman Musleh committed Mar 12, 2022
1 parent d4fcdf1 commit f10a484
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/OpenAPI.Net/OpenAPI.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageTags>cTrader, Open API, Spotware</PackageTags>
<Description>A .NET RX library for Spotware Open API</Description>
<PackageId>Spotware.OpenAPI.Net</PackageId>
<Version>1.3.9-rc0</Version>
<Version>1.3.9</Version>
<Platforms>AnyCPU</Platforms>
<Company>Spotware</Company>
<Authors>Spotware</Authors>
Expand Down
18 changes: 11 additions & 7 deletions src/OpenAPI.Net/OpenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public IDisposable Subscribe(IObserver<IMessage> observer)
/// <param name="clientMsgId">The client message ID (optional)</param>
/// <exception cref="InvalidOperationException">If getting message payload type fails</exception>
/// <returns>Task</returns>
public async Task SendMessage<T>(T message, string clientMsgId = null) where T :
IMessage
public async Task SendMessage<T>(T message, string clientMsgId = null) where T : IMessage
{
var protoMessage = MessageFactory.GetMessage(message.GetPayloadType(), message.ToByteString(), clientMsgId);

Expand All @@ -185,8 +184,7 @@ public async Task SendMessage<T>(T message, string clientMsgId = null) where T :
/// <param name="payloadType">Message Payload Type (ProtoPayloadType)</param>
/// <param name="clientMsgId">The client message ID (optional)</param>
/// <returns>Task</returns>
public async Task SendMessage<T>(T message, ProtoPayloadType payloadType, string clientMsgId = null) where T :
IMessage
public async Task SendMessage<T>(T message, ProtoPayloadType payloadType, string clientMsgId = null) where T : IMessage
{
var protoMessage = MessageFactory.GetMessage(message, payloadType, clientMsgId);

Expand All @@ -201,8 +199,7 @@ public async Task SendMessage<T>(T message, ProtoPayloadType payloadType, string
/// <param name="payloadType">Message Payload Type (ProtoOAPayloadType)</param>
/// <param name="clientMsgId">The client message ID (optional)</param>
/// <returns>Task</returns>
public async Task SendMessage<T>(T message, ProtoOAPayloadType payloadType, string clientMsgId = null) where T :
IMessage
public async Task SendMessage<T>(T message, ProtoOAPayloadType payloadType, string clientMsgId = null) where T : IMessage
{
var protoMessage = MessageFactory.GetMessage(message, payloadType, clientMsgId);

Expand Down Expand Up @@ -457,7 +454,14 @@ private async void SendHeartbeat()
{
if (IsDisposed || DateTimeOffset.Now - LastSentMessageTime < _heartbeatInerval) return;

await SendMessage(_heartbeatEvent, ProtoPayloadType.HeartbeatEvent).ConfigureAwait(false);
try
{
await SendMessage(_heartbeatEvent, ProtoPayloadType.HeartbeatEvent).ConfigureAwait(false);
}
catch (Exception ex)
{
OnError(ex);
}
}

/// <summary>
Expand Down

0 comments on commit f10a484

Please sign in to comment.