async void CloseIotHubConnection(IChannelHandlerContext context, PublishPacket will) { if (!this.ConnectedToHub) { // closure happened before IoT Hub connection was established or it was initiated due to disconnect return; } try { this.publishProcessor.Complete(); this.publishPubAckProcessor.Complete(); this.publishPubRecProcessor.Complete(); this.pubRelPubCompProcessor.Complete(); await Task.WhenAll( this.CompletePublishAsync(context, will), this.publishPubAckProcessor.Completion, this.publishPubRecProcessor.Completion, this.pubRelPubCompProcessor.Completion); IMessagingServiceClient hub = this.messagingServiceClient; this.messagingServiceClient = null; await hub.DisposeAsync(); } catch (Exception ex) { MqttIotHubAdapterEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString()); } }
async void ShutdownOnReceiveError(IChannelHandlerContext context, string exception) { this.publishPubAckProcessor.Abort(); this.publishProcessor.Abort(); this.publishPubRecProcessor.Abort(); this.pubRelPubCompProcessor.Abort(); IMessagingServiceClient hub = this.messagingServiceClient; if (hub != null) { this.messagingServiceClient = null; try { await hub.DisposeAsync(); } catch (Exception ex) { MqttIotHubAdapterEventSource.Log.Info("Failed to close IoT Hub Client cleanly.", ex.ToString()); } } ShutdownOnError(context, "Receive", exception); }