CyberDNS / Lupusec2Mqtt

Lupusec Alarm System to Mqtt
MIT License
11 stars 6 forks source link

Reconnect after connection loss #22

Closed chheiss closed 1 year ago

chheiss commented 3 years ago

Hi! Not sure if I had asked before, but it would be really great to get the plugin to reconnect after a few minutes, when there has been a connection drop. Thanks!

CyberDNS commented 3 years ago

Hi, does the connection drop on Lupusec system or homeassistant MQTT?

chheiss commented 3 years ago

Lupusec system is disconnected for a few seconds every few hours. Mqtt stays connected all the time.

CyberDNS commented 3 years ago

Do you see some kind of exception in the logs when the disconnection occurs or after the disconnection during the next poll?

chheiss commented 3 years ago

No, as I don't know when exactly the disconnect occurs, it is once every 24h. When I restart the plugin, it works again.

allgrinder commented 2 years ago

hey, I have exactly the same problem. The addon loses the connection every 24 hours! After restarting the addon everything works fine again.

The latest version of HA, MQTT and your addon is installed in use.

CyberDNS commented 2 years ago

Hi, Do you get after the disconnection still those messages or not?

[19:38:59 INF] Polling... (Every 5th cycle is logged) {"SourceContext": "Lupusec2Mqtt.Lupusec.PollingHostedService"}

And after disconnection, you have no errors/exceptions in the logs? Best regards, David

CyberDNS commented 2 years ago

And set this value in the config to Debug.

image

allgrinder commented 2 years ago

Thanks! I set it up that way now. Nevertheless, I have had a stable connection for 4 days. As soon as there are problems again - I'll post the log

xsus95 commented 2 years ago

Hi, same problem for me with following in lupusec-addon protocoll:

[06:04:46 INF] Polling... (Every 5th cycle is logged) {"SourceContext": "Lupusec2Mqtt.Lupusec.PollingHostedService"} [06:04:52 ERR] Call to Lupusec has an error! Request was: Method: POST, RequestUri: 'https://1**********/action/recordListGet', Version: 1.1, Content: <null>, Headers: { Accept: application/json Authorization: Basic ************ X-Token: ********** } {"SourceContext": "Lupusec2Mqtt.Lupusec.LupusecService"} System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing. ---> System.TimeoutException: The operation was canceled. ---> System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled. ---> System.Net.Sockets.SocketException (125): Operation canceled --- 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 System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](TIOAdapter adapter) at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory1 buffer) at System.Net.Http.HttpConnection.FillAsync(Boolean async) at System.Net.Http.HttpConnection.ChunkedEncodingReadStream.CopyToAsyncCore(Stream destination, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.ChunkedEncodingReadStream.CopyToAsyncCore(Stream destination, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionResponseContent.SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken) at System.Net.Http.HttpContent.LoadIntoBufferAsyncCore(Task serializeToStreamTask, MemoryStream tempBuffer) at System.Net.Http.HttpClient.gCore|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 100 [06:04:52 ERR] Message: Object reference not set to an instance of an object. {"SourceContext": "Lupusec2Mqtt.Lupusec.PollingHostedService"} System.NullReferenceException: Object reference not set to an instance of an object. at Lupusec2Mqtt.Lupusec.PollingHostedService.PublishSensor(RecordList recordList, Sensor sensor) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 214 at Lupusec2Mqtt.Lupusec.PollingHostedService.TryCall[T](T subject, Action1 action) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 258 [06:04:52 ERR] Message: Object reference not set to an instance of an object. {"SourceContext": "Lupusec2Mqtt.Lupusec.PollingHostedService"} System.NullReferenceException: Object reference not set to an instance of an object. at Lupusec2Mqtt.Lupusec.PollingHostedService.PublishSensor(RecordList recordList, Sensor sensor) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 214 at Lupusec2Mqtt.Lupusec.PollingHostedService.TryCall[T](T subject, Action1 action) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 258 [06:04:52 ERR] Message: Object reference not set to an instance of an object. {"SourceContext": "Lupusec2Mqtt.Lupusec.PollingHostedService"} System.NullReferenceException: Object reference not set to an instance of an object. at Lupusec2Mqtt.Lupusec.PollingHostedService.PublishSensor(RecordList recordList, Sensor sensor) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 214 at Lupusec2Mqtt.Lupusec.PollingHostedService.TryCall[T](T subject, Action1 action) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 258 [06:04:54 ERR] Call to Lupusec has an error! Request was: Method: POST, RequestUri: 'https:**********/action/deviceListGet', Version: 1.1, Content: <null>, Headers: { Accept: application/json Authorization: Basic ************ X-Token: ***************** } {"SourceContext": "Lupusec2Mqtt.Lupusec.LupusecService"} System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing. ---> System.TimeoutException: A task was canceled. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Lupusec2Mqtt.Lupusec.LupusecTokenHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecTokenHandler.cs:line 24 at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.gCore|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 100 Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Lupusec2Mqtt.Lupusec.PollingHostedService.PublishSensors() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 193 at Lupusec2Mqtt.Lupusec.PollingHostedService.DoWork(Object state) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/PollingHostedService.cs:line 158 at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()`

and following in mosquitto log (thousands of log entries): 1655095731: New connection from 172.30.32.2:48936 on port 1883. 1655095731: Client <unknown> closed its connection. 1655095851: New connection from 172.30.32.2:48938 on port 1883. 1655095851: Client <unknown> closed its connection. 1655095971: New connection from 172.30.32.2:48940 on port 1883. 1655095971: Client <unknown> closed its connection. 1655096091: New connection from 172.30.32.2:48942 on port 1883. 1655096091: Client <unknown> closed its connection. 1655096192: Saving in-memory database to /data//mosquitto.db. 1655096211: New connection from 172.30.32.2:48944 on port 1883. 1655096211: Client <unknown> closed its connection. 1655096331: New connection from 172.30.32.2:48946 on port 1883. 1655096331: Client <unknown> closed its connection. 1655096451: New connection from 172.30.32.2:48948 on port 1883. 1655096451: Client <unknown> closed its connection. 1655096571: New connection from 172.30.32.2:48950 on port 1883. 1655096571: Client <unknown> closed its connection.

These are not IP addresses from my IP range as they occur in my network. If I restart Mosquitto first and then Lupusec Addon, everything works again for a while.

CyberDNS commented 2 years ago

Hi @xsus95 ,

Thanks for the exception message, I think this helps to identify the problem. I will investigate this during the next days if I have the time.

Best regards, David

xsus95 commented 2 years ago

@CyberDNS

Hey, Yesterday I disconnected the network connection for a short time. However, there was no message in the Lupus Addon afterwards. In the Mosuqitto log, however, I still have these messages as already written now permanently. BUT: The connection is still running and hassio gets all changes of the states of my Lupus sensors. So a short interruption of the connection can not necessarily be the cause... I am confused.

CyberDNS commented 1 year ago

I will close this issue.

If it is still present in the current version, please open a new issue.