Open FalcoGer opened 4 years ago
Upon further examining the log I found this bit
Jul 18 20:02:22 logger-pi KNX_Logger.sh[13144]: 6/0/82 received data from 7.1.11 but it is not tracked.
Jul 18 20:02:22 logger-pi KNX_Logger.sh[13144]: Data: 0x2B 0x34 0x18 0x41 (00101011 00110100 00011000 01000001)
Jul 18 20:02:24 logger-pi KNX_Logger.sh[13144]: 6/0/80 received data from 7.1.11 but it is not tracked.
Jul 18 20:02:24 logger-pi KNX_Logger.sh[13144]: Data: 0x2C 0x14 (00101100 00010100)
Jul 18 20:02:31 logger-pi KNX_Logger.sh[13144]: [DELEGATE] Disconnected.
Jul 18 20:02:42 logger-pi KNX_Logger.sh[13144]: No knx-connection during main loop. Attempted reconnects so far: 0
Jul 18 20:02:46 logger-pi KNX_Logger.sh[13144]: [DELEGATE] Connected to KNX.
Jul 18 20:02:46 logger-pi KNX_Logger.sh[13144]: No knx-connection during main loop. Attempted reconnects so far: 1
Jul 18 20:02:51 logger-pi KNX_Logger.sh[13144]: 6/0/81 received data from 7.1.11 but it is not tracked.
Jul 18 20:02:51 logger-pi KNX_Logger.sh[13144]: Data: 0xE4 0xE0 0x00 0x41 (11100100 11100000 00000000 01000001)
Jul 18 20:02:51 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 02:51.832: ID: KNXLib.KnxReceiverTunnelingMSG: A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: 6/0/82 received data from 7.1.11 but it is not tracked.
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: Data: 0x2B 0x34 0x18 0x41 (00101011 00110100 00011000 01000001)
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 02:52.062: ID: KNXLib.KnxReceiverTunnelingMSG: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected h
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 02:52.064: ID: KNXLib.KnxReceiverTunnelingMSG: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean thr
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:02:52 logger-pi KNX_Logger.sh[13144]: [DELEGATE] Disconnected.
Which seems to be the start of all of that trouble.
In my KNX-Class I set a boolean variable false whenever the Disconnected
Delegate is called, and true whenever the Connected
Delegate is called. I use that to decide if I want to call the connect function in the main loop using this bit of code.
if (knx.ConnectedState == false)
{
Console.WriteLine("No knx-connection during main loop. Attempted reconnects so far: " + reconnectAttempts.ToString());
// this is 5 seconds
Thread.Sleep(RECONNECT_DELAY); // sleep for a bit to prevent spamming while attempting reconnecting
knx.Connect();
reconnectAttempts++;
if (reconnectAttempts > MAX_RECONNECT_ATTEMPTS)
{
throw new Exception("Reconnect failed " + reconnectAttempts.ToString() + " times in a row.");
}
}
else
{
reconnectAttempts = 0;
}
For some reason the disconnect delegate was called, the variable was set false. But then when reconnecting it didn't set the variable in the connected delegate? Perhaps it happened like so:
I made a shell script to launch my program in a loop in case my programm exits for any reason. While rare, the programm occasionally encounters a situation in which it has to reset. One of those situations is when it fails to connect to the KNX-Tunneling interface 10 times in a row. Then I decide to just restart the program and have everything in a known state.
Just today I had checked in on my project and found the service running, but no data being logged for 5 days. Examining the journal I found this:
After which I restarted...
There are some issues here that I don't fully understand:
There is no code between printing
Shutdown complete. Exiting.
andreturn 0
in theMain
function,so this has to come from a thread, however i already set the connection to
null
at that point.The most pressing issue is that the shell script output that runs the program in a loop never triggered, meaning the shell script hung on the program launch. and systemd told me the program was running.
I suspect some thread was at work here and didn't quit properly when the main programm returned from execution, letting the program "hang" in a state where it should've exited.
Could you please look into this and please mark all threads as
IsBackground = true
.The code I use for quitting is this:
Main:
KNX
My shell script:
"Stopped" was never written to startLog