OpenCyphal-Garage / cyraft

Raft algorithm (for pycyphal)
2 stars 2 forks source link

No response from request_vote #1

Closed maksimdrachov closed 1 year ago

maksimdrachov commented 1 year ago

I'm trying to get a response from request_vote, after sending a request using Yakut.

The issue is that I'm not getting any response, and the request times out:

issue-1-no-response

The demo node does appear to receive the request correctly:

issue-1-request-received

(When running in debug mode, putting a breakpoint on the entrance of _serve_request_vote, it appears to hang on the return statement)

The code implementing this request_vote functionality is as follows:

This is pretty much the same way it is done in the demo example from pycyphal.

The only thing I'm unclear about is whether it might have something to do the way run() is implemented:

async def run(self) -> None:
    """
    The main method that runs the business logic. It is also possible to use the library in an IoC-style
    by using receive_in_background() for all subscriptions if desired.
    """
    _logger.info("Application Node started!")
    _logger.info("Running. Press Ctrl+C to stop.")

    while True:
        await asyncio.sleep(0.1)

In the demo example, there's more setup code here, however nothing related to the service (least_square in their case.)

I suspect maybe I need to use the library in "IoC-style by using receive_in_background()", however not sure how this looks in code, please bear with me and use simple words.

pavel-kirienko commented 1 year ago

The code looks correct to me, at least I don't see any obvious issues. Which transport are you using and what is the node-ID of Yakut? You should inspect verbose logs from both Yakut and your application. There will be a lot of output but in that output there will be useful information regarding the lost transfer. At least you'll know if the response is actually being sent.

maksimdrachov commented 1 year ago

Ok, it was this:

@staticmethod
async def _serve_request_vote(
    # self,
    request: sirius_cyber_corp.RequestVote_1.Request,
    metadata: pycyphal.presentation.ServiceRequestMetadata,
) -> sirius_cyber_corp.RequestVote_1.Response:
    _logger.info(
        "\033[94m Request vote request %s from node %d \033[0m",
        request,
        metadata.client_node_id,
    )

    return sirius_cyber_corp.RequestVote_1.Response(
        term=1,
        voteGranted=True, # <---- previously wrong argument name here
    )

Shows up in the log as follows:

image