From 238dee12d07c0d1ea8aa3bb51bdba6c95bfab6bb Mon Sep 17 00:00:00 2001 From: Frank Bakker Date: Mon, 19 Dec 2022 22:36:17 +0100 Subject: [PATCH] Fix #815, TaskCanceledException when calling service from Dispose(Async) by avoiding Result-Handling task from being cancelled --- .../NetDaemon.HassClient/Internal/HomeAssistantConnection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Client/NetDaemon.HassClient/Internal/HomeAssistantConnection.cs b/src/Client/NetDaemon.HassClient/Internal/HomeAssistantConnection.cs index c63b7f04e..0207f631d 100644 --- a/src/Client/NetDaemon.HassClient/Internal/HomeAssistantConnection.cs +++ b/src/Client/NetDaemon.HassClient/Internal/HomeAssistantConnection.cs @@ -76,7 +76,9 @@ private async Task> SendCommandAsyncInternal(T command, Can // this task will be returned and handled by caller var resultEvent = _hassMessageSubject .Where(n => n.Type == "result" && n.Id == command.Id) - .FirstAsync().ToTask(cancelToken); + .FirstAsync().ToTask(CancellationToken.None); + // We dont want to pass the incoming CancellationToken here because it will throw a TaskCanceledException + // when calling services from an Apps Dispose(Async) and hide possible actual exceptions await _transportPipeline.SendMessageAsync(command, cancelToken);