capnproto / pycapnp

Cap'n Proto serialization/RPC system - Python bindings
BSD 2-Clause "Simplified" License
458 stars 125 forks source link

Debugging server/client function calls #327

Closed lenianiva closed 9 months ago

lenianiva commented 9 months ago

Is there a way to debug capnp to see which function is called?

In my use case, I have a schema like this for bidirectional streaming:

interface Process {
    stream @1 (callbackTarget :CallbackTarget) -> (callbackAction :CallbackAction);

    interface CallbackTarget {
        sendTarget @0 (target :Text) -> ();
    }
    interface CallbackAction {
        sendAction @0 (response :Text) -> ();
    }
}

and a client (simplified version)

class AgentHandle(protocol.agent_capnp.Process.CallbackTarget.Server):
    def __init__(self, agent):
        self.agent = agent
        self.queue_action = asyncio.Queue(maxsize=5)

        assert 'sendTarget' in protocol.agent_capnp.Process.CallbackTarget.schema.method_names

    async def start(self, callback_action):
        while response := await self.queue_action.get() is not None:
            result = callback_action.sendAction(response=response)
            respond = await result.a_wait()

    def sendTarget(self, target, **args):
        ... # Query the agent about the target
        await self.queue_action.put(...)

This is in the main function

        agent_handle = AgentHandle(agent)
        stream_reply: capnp.Promise = server.stream(
            callbackTarget=agent_handle
        )
        logging.info("Calling server to start tactic stream")
        stream_reply = await stream_reply.a_wait()
       # The server shows that the above `.stream` call has been received
        callback_action = stream_reply.callbackAction

        logging.info("Starting stream ...")
        await agent_handle.start(callback_action)

However the sendTarget function is never called, and the server I have (in rust) shows that the sendTarget promise never returns when .await is called on it. Is there a general method for debugging this type of problems?

lenianiva commented 9 months ago

The problem was that I did not use async socket connection as described here