Skip to content
Snippets Groups Projects
Commit e768c073 authored by jkerdreu's avatar jkerdreu
Browse files

Fix the nasty timing bug w/ Python asyncio.Protocol. The API reports the transport as "connected",

but the IGMP packet wasn't sent yet. So we are receiving answers before we managed to effectly 
join the multicast group.

Here an example (tshark) with is a is_alive query: 

1 0.000000000  10.77.3.105 → 224.0.29.200 UDP 120 1236 → 1236 Len=78   <-- notify is_alive
2 0.000033024  10.77.3.105 → 224.0.29.200 UDP 150 1236 → 1236 Len=108  <-- request is_alive
3 0.007238730  10.77.3.105 → 224.0.29.200 IGMPv2 46 MRG 224.0.29.200   <-- Multicast join

The average delay is around 8ms on a container based install (with 802.1q, and bridges) 
The only solution right now is to wait (50ms) in AsycnNetworkConnector.connect().

After the patch, you should experience something like this: 

1 0.000000000  10.77.3.105 → 224.0.29.200 IGMPv2 46 MRG 224.0.29.200
2 0.043197464  10.77.3.105 → 224.0.29.200 UDP 120 1236 → 1236 Len=78
3 0.043218241  10.77.3.105 → 224.0.29.200 UDP 150 1236 → 1236 Len=108
4 0.046509230   10.77.3.64 → 224.0.29.200 UDP 122 1236 → 1236 Len=80
5 0.047613517   10.77.3.64 → 224.0.29.200 UDP 122 1236 → 1236 Len=80
6 0.049329272   10.77.3.64 → 224.0.29.200 UDP 123 1236 → 1236 Len=81

Yes, first device answers within 3.3ms.. so < 8ms. 

This bug only occurs on host with no other xAAL apps running on the same address/port and only
at startup.




git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3145 b32b6428-25c9-4566-ad07-03861ab6144f
parent a384d3df
Branches
No related tags found
No related merge requests found
......@@ -534,8 +534,7 @@ def is_alive():
else:
print(f"{msg.source}: {msg.dev_type}")
async def start():
await asyncio.sleep(0.1)
def start():
print(LINE)
helper.request_is_alive(dev_type=dev_type)
......
......@@ -21,6 +21,9 @@ class AsyncNetworkConnector(object):
on_con_lost = loop.create_future()
self.transport, self.protocol = await loop.create_datagram_endpoint(
lambda: XAALServerProtocol(on_con_lost,self.receive), sock = self.new_sock())
# In some conditions (containers), transport is connected but IGMP is delayed (up to 10ms)
# so we need to wait for IGMP to be really sent.
await asyncio.sleep(0.05)
def new_sock(self):
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM,socket.IPPROTO_UDP)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment