-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
The issue could be solved via one of:
- Prevent messages from even being generated: Wait for nodes to identify themselves (via responses to global messages) before sending messages (such as queries or Standard responses). The problem would remain that an application could cause the alias map KeyError. That doesn't seem like a complete solution, because the application actually can't know whether there will be an alias map reset even in the short time between if it checks the validity before sending a Message, considering parallelism. It seems like the responsibility of python-openlcb to ensure a valid state and usage of its concrete implementation/internals.
- Cancel the message on alias map KeyError (to prevent issues with parallelism as in the time between checking and using, handle KeyError instead)
- A separate queue (dequeued via callbacks when mapped): I spoke to Balazs about: Generated NodeIDs may be leaked onto network (also happens in LccTools) #91 and there isn't typically a reason to send a Message if you don't have a destination, unless it is global. However, Balazs said openmrn (may) have a separate queue for Messages where the NodeID is still pending (in the form of a hashmap [probably a hashmap of queues] so mapping NodeID can immediately trigger moving it to a send queue). I actually can't see much of a benefit of a delayed queue rather than canceling the Message. Even if it is a state change intended by the user it is the responsibility of the application (not python-openlcb), at least to the extent of ensuring it was acknowledged--(?) Any thoughts?
It is avoidable via no. 1 for now, but here is a crash log with my branch in the PR (The crash only happens occasionally when example_cd_access.py runs, so apparently it is a race condition) just for reference--This log event could be considered artificial since the NodeID was entered manually (but demonstrates the issue since the same undefined behavior could occur at the same point in the code after any removal or clearing of the alias maps).
C:\Users\first\git\python-openlcb\openlcb\canbus\canphysicallayer.py:66: UserWarning: [registerFrameReceivedListener] You don't really need to listen to packets. Use pollFrame instead, which will collect and decode packets into frames (this layer communicates to upper layers using physicalLayer.onFrameReceived set by LinkLayer/subclass constructor).
warnings.warn(
QUEUE frames : link up...
[CanLink handleFrameReceived] control_frame=ControlFrame.LinkUp
[CanLink] done calling defineAndReserveAlias.
QUEUED frames : link up...waiting...
[linkStateChange] Link_Layer_Up
SENT frames : link up
This example will exit on failure or complete data.
Requesting memory read. Please wait...
Did not know destination = 09.00.99.03.00.0F on datagram send self.nodeIdToAlias={09.00.99.01.03.FF: 998, 06.01.00.00.C8.FC: 232, 06.01.00.00.C8.44: 123, 06.01.00.00.C3.58: 14, 06.01.00.00.00.03: 3783, 06.01.00.00.D1.FD: 3674}. Ensure recv loop (such as OpenLCBNetwork's _listen thread) is running before and during alias reservation sequence delay. Check previous log messages for an exception that may have ended the recv loop.
nodeIdToAlias updated: {09.00.99.01.03.FF: 998, 06.01.00.00.C8.FC: 232, 06.01.00.00.C8.44: 123, 06.01.00.00.C3.58: 14, 06.01.00.00.00.03: 3783, 06.01.00.00.D1.FD: 3674}
nodeIdToAlias updated: {09.00.99.01.03.FF: 998, 06.01.00.00.C8.FC: 232, 06.01.00.00.C8.44: 123, 06.01.00.00.C3.58: 14, 06.01.00.00.00.03: 3783, 06.01.00.00.D1.FD: 3674, 06.01.00.00.C9.D5: 3565, 09.00.99.03.00.0F: 3456}
Exception in thread Thread-1 (memoryRead):
Traceback (most recent call last):
File "C:\Python312-Win7\Lib\threading.py", line 1075, in _bootstrap_inner
self.run()
File "C:\Python312-Win7\Lib\threading.py", line 1012, in run
self._target(*self._args, **self._kwargs)
File "c:\Users\first\git\python-openlcb\examples\example_cdi_access.py", line 308, in memoryRead
memoryService.requestMemoryRead(memMemo)
File "C:\Users\first\git\python-openlcb\openlcb\memoryservice.py", line 188, in requestMemoryRead
self.requestMemoryReadNext(memo)
File "C:\Users\first\git\python-openlcb\openlcb\memoryservice.py", line 217, in requestMemoryReadNext
self.service.sendDatagram(dgWriteMemo)
File "C:\Users\first\git\python-openlcb\openlcb\datagramservice.py", line 167, in sendDatagram
self.sendDatagramMessage(memo)
File "C:\Users\first\git\python-openlcb\openlcb\datagramservice.py", line 173, in sendDatagramMessage
self.linkLayer.sendMessage(message)
File "C:\Users\first\git\python-openlcb\openlcb\canbus\canlink.py", line 892, in sendMessage
dddAlias = self.nodeIdToAlias[msg.destination]
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 09.00.99.03.00.0F
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels