Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: mqtt connection loop in v2.1.0 #171

Open
2 of 4 tasks
DanielTerletzkiy opened this issue Sep 28, 2024 · 10 comments
Open
2 of 4 tasks

Bug: mqtt connection loop in v2.1.0 #171

DanielTerletzkiy opened this issue Sep 28, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@DanielTerletzkiy
Copy link

Describe the bug
after updating to v2.1.0 the MQTT tries to connect, connects successfully for like 1sec and tries to reconnect over and over again

To Reproduce
Steps to reproduce the behavior:

  1. install v2.1.0
  2. do the config migration in the installer
  3. MQTT is looping

Expected behavior
mqtt should connect and stay connected

Screenshots
homescreen mqtt going from "running" to "connecting" quickly

Misc info (please complete the following information):

  • Windows build (ideally screenshot/info of winver.exe output): 24H2 Build 26100.1591
  • Windows' UI language:
  • HASS.Agent version: 2.1.0

Please check what's applicable (multiple answers possible):

  • Installed via installer
  • Installed manually
  • Problem occurs in HASS.Agent
  • Problem occurs in Satellite Service

Additional context
after a while it connected for 2 whole minutes and started looping again

Logs

2024-09-28 15:36:00.601 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:00.652 +02:00 [INF] [NOTIFIER] Ready
2024-09-28 15:36:01.254 +02:00 [INF] [LOCALAPI] listening on port 5115
2024-09-28 15:36:02.084 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:02.628 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:02.630 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:03.107 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:03.298 +02:00 [INF] [HASS_API] Home Assistant version: 2024.9.3
2024-09-28 15:36:03.537 +02:00 [INF] [HASS_API] System connected with https://homeassistant.local:8123/
2024-09-28 15:36:03.638 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:03.639 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:04.117 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:04.666 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:04.667 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:05.118 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:05.684 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:05.684 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:06.131 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:06.701 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:06.702 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:07.145 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:07.713 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:07.714 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:08.159 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:08.725 +02:00 [INF] [MQTT] Connected
2024-09-28 15:36:08.726 +02:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-28 15:36:09.174 +02:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-28 15:36:09.739 +02:00 [INF] [MQTT] Connected

@DanielTerletzkiy DanielTerletzkiy added the bug Something isn't working label Sep 28, 2024
@amadeo-alex
Copy link
Collaborator

amadeo-alex commented Sep 29, 2024

Could you please enable extended logging and then paste the logs here?
I assume the only "variable" is the HASS.Agent update, no MQTT broker updates also etc?
Which MQTT broker are you using?
What is the grace period that you have configured?

@matheusvellone
Copy link

I'm getting this loop randomly too.

Using Mosquitto docker image as a broker

What is the grace period that you have configured?

I don't know. I guess the default one


When I restarted the agent to enable extendes logs, MQTT took a while to connect and then failed. Right after failing, it connected

Logs from the start until it connected successfully (i guess)
2024-09-30 08:55:25.846 -03:00 [INF] [MAIN] HASS.Agent version: 2.1.0
2024-09-30 08:55:25.850 -03:00 [INF] [MAIN] Extended logging enabled
2024-09-30 08:55:25.854 -03:00 [INF] [SETTINGS] Config storage path: C:\Users\mathe\AppData\Local\HASS.Agent\Client\config
2024-09-30 08:55:25.958 -03:00 [INF] [SETTINGS] Configuration loaded
2024-09-30 08:55:25.962 -03:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2024-09-30 08:55:26.425 -03:00 [DBG] [RADIOMGR] Initialization started
2024-09-30 08:55:26.474 -03:00 [INF] [RADIOMGR] Radio management permission granted
2024-09-30 08:55:26.474 -03:00 [DBG] [RADIOMGR] Enumerating proximity/NFC devices
2024-09-30 08:55:26.494 -03:00 [INF] [RADIOMGR] Ready
2024-09-30 08:55:28.541 -03:00 [INF] [INTERNALSENSORS] Ready
2024-09-30 08:55:30.672 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_ISABUS.HTP.Method' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_ISABUS.HTP.Method' is denied.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:30.673 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_ISABUS.HTP.Method' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_ISABUS.HTP.Method' is denied.
   at System.Threading.Mutex.OpenExistingWorker(String name, Mutex& result)
   at System.Threading.Mutex.OpenExisting(String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:30.673 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_PCI' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_PCI' is denied.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:30.673 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_PCI' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_PCI' is denied.
   at System.Threading.Mutex.OpenExistingWorker(String name, Mutex& result)
   at System.Threading.Mutex.OpenExisting(String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:30.673 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_EC' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_EC' is denied.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:30.673 -03:00 [FTL] [PROGRAM] FirstChanceException: Access to the path 'Global\Access_EC' is denied.
System.UnauthorizedAccessException: Access to the path 'Global\Access_EC' is denied.
   at System.Threading.Mutex.OpenExistingWorker(String name, Mutex& result)
   at System.Threading.Mutex.OpenExisting(String name)
   at LibreHardwareMonitor.Hardware.Mutexes.<Open>g__CreateOrOpenExistingMutex|4_0(String name)
2024-09-30 08:55:31.286 -03:00 [INF] [VIRTDESKT] Virtual Desktop Manager initialized
2024-09-30 08:55:31.286 -03:00 [DBG] [AUDIOMGR] initializing
2024-09-30 08:55:31.789 -03:00 [INF] [AUDIOMGR] initialized
2024-09-30 08:55:31.801 -03:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded
2024-09-30 08:55:31.802 -03:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded
2024-09-30 08:55:31.836 -03:00 [INF] [SETTINGS_SENSORS] Loaded 3 entities
2024-09-30 08:55:31.842 -03:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2024-09-30 08:55:31.897 -03:00 [INF] [LOCALAPI] Disabled
2024-09-30 08:55:31.935 -03:00 [INF] [MQTT] Identifying as device: DESKTOP-3B27FBK
2024-09-30 08:55:31.941 -03:00 [INF] [MQTT] Connecting ..
2024-09-30 08:55:31.949 -03:00 [INF] [SERVICE] Local install path: C:\Program Files\HASS.Agent\Service\
2024-09-30 08:55:31.995 -03:00 [INF] [MEDIA] Ready
2024-09-30 08:55:32.009 -03:00 [INF] [MEDIA] Now playing: AchismosTV - DE MÚSICO SEM SORTE A COMEDIANTE DE SUCESSO FT. FABIANO CAMBOTA  | #ACHISMOS PODCAST #329
2024-09-30 08:55:32.031 -03:00 [WRN] [MQTT] Not connected, message dropped (won't report again for 5 minutes)
2024-09-30 08:55:32.032 -03:00 [INF] [MEDIA] New state: Playing
2024-09-30 08:55:32.062 -03:00 [INF] [NOTIFIER] Ready
2024-09-30 08:55:32.075 -03:00 [INF] [HASS_API] Home Assistant version: 2024.5.0
2024-09-30 08:55:32.184 -03:00 [INF] [HASS_API] System connected with REDACTED
2024-09-30 08:55:53.003 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
2024-09-30 08:55:53.004 -03:00 [FTL] [NET] FirstChancemqttCommunicationException: The operation has timed out.
MQTTnet.Exceptions.MqttCommunicationTimedOutException: The operation has timed out.
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2024-09-30 08:56:53.150 -03:00 [WRN] [MQTT] Disconnected: UnspecifiedError
2024-09-30 08:56:53.167 -03:00 [ERR] [MQTT] Error while connecting: Connection timed out
2024-09-30 08:56:58.221 -03:00 [INF] [MQTT] Connected
2024-09-30 08:56:58.378 -03:00 [INF] [MQTT] Initial registration completed
2024-09-30 08:57:20.822 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 08:57:20.822 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
2024-09-30 08:57:20.823 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 08:57:20.823 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.823 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 08:57:20.823 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.823 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2024-09-30 08:57:20.823 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.823 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.824 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2024-09-30 08:57:20.824 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.824 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.825 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:20.825 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:57:21.349 -03:00 [INF] [MQTT] Connected
2024-09-30 08:57:21.350 -03:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-30 08:58:12.885 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
2024-09-30 08:58:12.885 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 08:58:12.885 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.885 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 08:58:12.885 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 08:58:12.885 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.885 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-30 08:58:12.885 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.885 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.885 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
2024-09-30 08:58:12.885 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
2024-09-30 08:58:12.886 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.886 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.886 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:12.886 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.AnnounceAvailabilityAsync(Boolean offline) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 509
2024-09-30 08:58:12.886 -03:00 [FTL] [MQTT] Error while announcing availability: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.AnnounceAvailabilityAsync(Boolean offline) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 509
2024-09-30 08:58:12.886 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 08:58:13.672 -03:00 [INF] [MQTT] Connected
2024-09-30 08:58:13.673 -03:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-30 08:59:34.797 -03:00 [INF] [MEDIA] Now playing: Mamonas Assassinas - 1406
2024-09-30 08:59:34.802 -03:00 [INF] [MEDIA] New state: Paused
2024-09-30 09:00:29.196 -03:00 [INF] [MEDIA] Now playing: AchismosTV - DE MÚSICO SEM SORTE A COMEDIANTE DE SUCESSO FT. FABIANO CAMBOTA  | #ACHISMOS PODCAST #329
2024-09-30 09:00:29.202 -03:00 [INF] [MEDIA] New state: Playing
2024-09-30 09:00:57.257 -03:00 [INF] [MEDIA] Now playing: Mamonas Assassinas - 1406
2024-09-30 09:00:57.261 -03:00 [INF] [MEDIA] New state: Paused
2024-09-30 09:01:54.614 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
2024-09-30 09:01:54.614 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.614 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.614 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 09:01:54.614 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 09:01:54.614 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ReadFixedHeaderAsync(CancellationToken cancellationToken)
2024-09-30 09:01:54.614 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.614 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-30 09:01:54.614 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.614 -03:00 [FTL] [NET] FirstChancemqttCommunicationException: The TCP connection is closed.
MQTTnet.Exceptions.MqttCommunicationException: The TCP connection is closed.
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
2024-09-30 09:01:54.615 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.615 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.615 -03:00 [FTL] [NET] FirstChancemqttCommunicationException: The TCP connection is closed.
MQTTnet.Exceptions.MqttCommunicationException: The TCP connection is closed.
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
2024-09-30 09:01:54.615 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.615 -03:00 [FTL] [MQTT] Error while announcing availability: The TCP connection is closed.
MQTTnet.Exceptions.MqttCommunicationException: The TCP connection is closed.
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.AnnounceAvailabilityAsync(Boolean offline) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 509
2024-09-30 09:01:54.615 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:54.615 -03:00 [FTL] [MQTT] Error publishing message: An existing connection was forcibly closed by the remote host.
2024-09-30 09:01:55.325 -03:00 [INF] [MQTT] Connected
2024-09-30 09:01:55.326 -03:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-30 09:02:46.295 -03:00 [INF] [MEDIA] Now playing: AchismosTV - DE MÚSICO SEM SORTE A COMEDIANTE DE SUCESSO FT. FABIANO CAMBOTA  | #ACHISMOS PODCAST #329
2024-09-30 09:02:46.300 -03:00 [INF] [MEDIA] New state: Playing
2024-09-30 09:03:09.537 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 09:03:09.537 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)

After this, I've been waiting for the conection failed notification and it didn't poped up, but I've found this logs which might be helpful

Logs
2024-09-30 09:16:41.207 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
 ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)
2024-09-30 09:16:41.207 -03:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
2024-09-30 09:16:41.208 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ReadFixedHeaderAsync(CancellationToken cancellationToken)
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ReadFixedHeaderAsync(CancellationToken cancellationToken)
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.208 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.PublishAsync(MqttApplicationMessage message) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 416
2024-09-30 09:16:41.209 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:41.209 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:16:44.392 -03:00 [INF] [MQTT] Connected
2024-09-30 09:16:44.392 -03:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)

If/when it fails I will post logs here

@matheusvellone
Copy link

It happened

2024-09-30 09:41:36.188 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Client.MqttClient.TrySendKeepAliveMessages(CancellationToken cancellationToken)
2024-09-30 09:41:36.188 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.188 -03:00 [FTL] [PROGRAM] FirstChanceException: A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at MQTTnet.Internal.AsyncQueue`1.TryDequeueAsync(CancellationToken cancellationToken)
2024-09-30 09:41:36.189 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
2024-09-30 09:41:36.189 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.189 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.189 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 09:41:36.189 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.189 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.189 -03:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.AnnounceAvailabilityAsync(Boolean offline) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 541
2024-09-30 09:41:36.189 -03:00 [FTL] [MQTT] Error while announcing availability: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.PublishAtMostOnce(MqttPublishPacket publishPacket, CancellationToken cancellationToken)
   at HASS.Agent.MQTT.MqttManager.AnnounceAvailabilityAsync(Boolean offline) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\MQTT\MqttManager.cs:line 541
2024-09-30 09:41:36.190 -03:00 [ERR] [NET] [ConnectionReset] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:36.190 -03:00 [ERR] [NET] [MqttCommunicationException.SocketException] An existing connection was forcibly closed by the remote host.
2024-09-30 09:41:48.387 -03:00 [INF] [MEDIA] Now playing: Mamonas Assassinas - 1406
2024-09-30 09:41:48.391 -03:00 [INF] [MEDIA] New state: Paused
2024-09-30 09:41:54.536 -03:00 [WRN] [MQTT] Not connected, message dropped (won't report again for 5 minutes)
2024-09-30 09:41:57.779 -03:00 [FTL] [NET] [TimedOut] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
2024-09-30 09:41:57.779 -03:00 [FTL] [NET] FirstChancemqttCommunicationException: The operation has timed out.
MQTTnet.Exceptions.MqttCommunicationTimedOutException: The operation has timed out.
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2024-09-30 09:42:36.344 -03:00 [WRN] [MQTT] Disconnected: UnspecifiedError
2024-09-30 09:42:57.884 -03:00 [ERR] [MQTT] Error while connecting: Connection timed out
2024-09-30 09:42:57.923 -03:00 [FTL] [PROGRAM] FirstChanceException: The operation was canceled.
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MQTTnet.Internal.BlockingQueue`1.PeekAndWait(CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.PublishQueuedMessagesAsync(CancellationToken cancellationToken)
2024-09-30 09:43:05.954 -03:00 [INF] [MQTT] Connected

@amadeo-alex
Copy link
Collaborator

I'm getting this loop randomly too.

Using Mosquitto docker image as a broker

What is the grace period that you have configured?

I don't know. I guess the default one

When I restarted the agent to enable extendes logs, MQTT took a while to connect and then failed. Right after failing, it connected
Logs from the start until it connected successfully (i guess)

After this, I've been waiting for the conection failed notification and it didn't poped up, but I've found this logs which might be helpful
Logs

If/when it fails I will post logs here

Thank you for pitching and and providing the logs!
The "System.ObjectDisposedException: Cannot access a disposed object." gives me a bit of a hint but I'll need to find a way to reproduce it as then fixing it will be much much easier (I haven't encountered this during the development)

Some additional questions if I may:

  • do you use username/password for MQTT connection?
  • do you use certificates for MQTT connection?
  • I assume as with Daniel, issue was not present on 2.0.1 (or betas?) and appeared with 2.1.0?

@DanielTerletzkiy
Copy link
Author

i use the home assistant mosquitto broker addon with username+password, without certificates
currently don't use any certificates and never had with hass-agent

@matheusvellone
Copy link

username + password too and without certificates

I updated from the legacy app to this one recently, but I remember updating to 2.1.0 after. I don't recall receiving this notifications before the update (but there is a chance I'm confused sorry)

@matheusvellone
Copy link

Looking at the logs right now I can see 532 occurrences of System.ObjectDisposedException: Cannot access a disposed object., but I dindn't receive 532 notifications along the day.

Here it is all different occurrences with the stack traces for the error you mentioned

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at MQTTnet.Adapter.MqttChannelAdapter.SendPacketAsync(MqttPacket packet, CancellationToken cancellationToken)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
   at System.Net.Sockets.NetworkStream.<ThrowIfDisposed>g__ThrowObjectDisposedException|63_0()
   at System.Net.Sockets.NetworkStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
   at MQTTnet.Implementations.MqttTcpChannel.WriteAsync(ArraySegment`1 buffer, Boolean isEndOfPacket, CancellationToken cancellationToken)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'AsyncLockWaiter'.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
   at System.Net.Sockets.NetworkStream.<ThrowIfDisposed>g__ThrowObjectDisposedException|63_0()
   at System.Net.Sockets.NetworkStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
   at System.Net.Sockets.NetworkStream.<ThrowIfDisposed>g__ThrowObjectDisposedException|63_0()

@amadeo-alex
Copy link
Collaborator

Ok so, I still wasn't able to fully replicate this, by this I mean the exception regarding disposed object.
I tried to do some changes that in theory should prevent a situation where the library tries to access the MQTT client after it has been disposed from what I can see the exceptions are coming directly from library rather than HASS.Agent itself.

But before I elaborate: to have any kind o test bed - MQTT status cycling between "running" and "connecting" - I had to run two instances of HASS.Agent that had the same MQTT settings (client id).
I'd like to ask you to check the MQTT (mosquitto) logs for something like this:
N8AtkW
Those are the logs from where I had two instances of HASS.Agent running - if the same logs appear while you're having the issues it means that there are two instances of HASS.Agent with "same" config running at the same time - which is bad of course.

Now going back to what I tried to do, there is a test build available here - https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.1-beta2-mqttdisposed - with the changes I mentioned at the beginning.
If possible try it (and check the MQTT logs before of course) and let me know if it changes anything.

@matheusvellone
Copy link

The day after reporting the problem it stopped giving the notification errors (i guess)

Didn't made any upgrades to any related container, but I had some manual restarts last weeks, maybe it helped making connections more stable. Now thats stable, can't reproduce it neither test the version you published 😕

@ManuVice
Copy link

I had the same problem. I have two Windows 11 users.

I have disabled "Automatic Sign-in after Update" in Settings/User and my loop was gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants