Menu

peer_status callback is not called if the remote coroutine is killed

2015-08-13
2015-08-15
  • Oscar Curero

    Oscar Curero - 2015-08-13

    Hi,

    I having problems with the peer_status callback when a remote corouting is killed. Let's see the code:

    server.py:

    1 import asyncoro.disasyncoro as asyncoro
    2
    3 def peers(coro=None):
    4 global connections
    5 while True:
    6 msg = yield coro.receive()
    7 if msg.status == 1:
    8 print "New node: " + msg.name
    9 connections[msg.name] = msg.location
    10 else:
    11 print "Node disconnected: " + msg.name
    12 del(connections[msg.name])
    13
    14 def server(coro=None):
    15 global connections
    16 connections = dict()
    17 peer_monitor = asyncoro.Coro(peers)
    18 scheduler = asyncoro.AsynCoro()
    19 scheduler.peer_status(peer_monitor)
    20 while True:
    21 if len(connections) > 0:
    22 node = yield coro.locate("client", connections.values()[0])
    23 node.send("Welcome!")
    24 yield coro.sleep(10)
    25
    26 scheduler = asyncoro.AsynCoro(node="127.0.0.1",
    27 udp_port=51350,
    28 tcp_port=50000,
    29 name="A")
    30 asyncoro.Coro(server)

    client.py:

    1 import asyncoro.disasyncoro as asyncoro
    2
    3 def client(coro=None):
    4 coro.register()
    5 yield scheduler.peer(asyncoro.Location("127.0.0.1", 50000))
    6 msg = yield coro.receive()
    7 print msg
    8 yield coro.sleep(30)
    9
    10 scheduler = asyncoro.AsynCoro(node="127.0.0.1",
    11 udp_port=51350,
    12 tcp_port=50001,
    13 name="B")
    14
    15 asyncoro.Coro(client)

    Run server.py. It will just wait for a peer to connect:

    oscar@gardenia:~/projects/asyncoro/src> python server.py
    2015-08-13 18:10:25,536 - asyncoro - network server "A" @ 127.0.0.1:50000, udp_port=51350

    Run client.py:

    oscar@gardenia:~/projects/asyncoro/src> python remote2.py
    2015-08-13 18:10:28,032 - asyncoro - network server "B" @ 127.0.0.1:50001, udp_port=51350

    As soon as the client "B" is connected to server "A", the <peer> coroutine is called and on the server.py it prints: >>"New node: B"
    The server coroutine on server "A" then will send the welcome message to client "B" and so the message will be printed:</peer>

    Welcome!

    At this point, if I kill client "B" while is still running no message will appear in the server "A". This may be correct, indeed client "B" just desapeeared from the network.

    However, if I run again client "B" I get some weired message about invalid messages:

    server.py:

    oscar@gardenia:~/projects/asyncoro/src> python server.py
    2015-08-13 18:10:25,536 - asyncoro - network server "A" @ 127.0.0.1:50000, udp_port=51350
    New node: B
    2015-08-13 18:11:35,604 - asyncoro - uncaught exception in server/3069625644@127.0.0.1:50000:
    Traceback (most recent call last):
    File "/home/oscar/projects/asyncoro/src/lib/python2.7/site-packages/asyncoro/init.py", line 3226, in _schedule
    retval = coro._generator.send(coro._value)
    File "remote1.py", line 42, in server
    node.send("Welcome!")
    AttributeError: 'NoneType' object has no attribute 'send'

    client.py:

    oscar@gardenia:~/projects/asyncoro/src> python client.py
    2015-08-13 18:12:42,337 - asyncoro - network server "B" @ 127.0.0.1:50001, udp_port=51350
    Welcome!
    killed
    oscar@gardenia:~/projects/asyncoro/src> python client.py
    2015-08-13 18:12:56,449 - asyncoro - network server "B" @ 127.0.0.1:50001, udp_port=51350
    2015-08-13 18:12:57,495 - asyncoro - invalid request locate_coro from None ignored: "67b79a70ad8c59f587a764ac95427aff06d05b27", "8cb7faaab9e722026c6dfcf130973051621f703a"

    As you can see, the problem is that when the client "B" connects for the second time after a sudden disconnect, the peer_status callback is not called. If the client exits clearly, then peer_status is called for the disconnect and everything works fine:

    server.py:

    oscar@gardenia:~/projects/asyncoro/src> python server.py
    2015-08-13 18:20:21,358 - asyncoro - network server "A" @ 127.0.0.1:50000, udp_port=51350
    New node: B
    Node disconnected: B
    New node: B
    Node disconnected: B

    client.py:

    oscar@gardenia:~/projects/asyncoro/src> python client.py
    2015-08-13 18:20:21,895 - asyncoro - network server "B" @ 127.0.0.1:50001, udp_port=51350
    Welcome!
    oscar@gardenia:~/projects/asyncoro/src>
    oscar@gardenia:~/projects/asyncoro/src> python client.py
    2015-08-13 19:20:51,987 - asyncoro - network server "B" @ 127.0.0.1:50001, udp_port=51350
    Welcome!

    Thanks!

     
  • Oscar Curero

    Oscar Curero - 2015-08-14

    trying to debug this issue, I found the root of my problem: on line 1057 in disasyncoro.py if a peer connects to us, it's checked if the peer is already on the peers list. Since the peer disconnected without notice, the peer is in still on the list and therefore the callback is not called.

    I commented that line and everything seems to run ok.

    Cheers,

     
  • Giridhar Pemmasani

    Thanks for loating and suggesting the fix. I have applied correct patch and committed to GitHub. This will be in next release.

     

Log in to post a comment.