rpclib icon indicating copy to clipboard operation
rpclib copied to clipboard

Terminating the server via RPC call

Open sasmaster opened this issue 7 years ago • 9 comments

Hi. I am not sure if it's a bug or my misunderstanding of documentation. I would like to terminate a process via rpc message. Now,the thing is ,there is rpc server loop which needs to be closed,right?

So I wrote a message handler like this:

   ```

rpc::server srv(rpc::constants::DEFAULT_PORT); //Process terminate callback srv.bind("close", { rpc::this_server_t server = rpc::this_server(); server.stop(); return 1; });


Because a comment for rpc::this_server() states "A thread-local object that can be used to control
 the behavior of the server w.r.t. the handler." ,I assumed that I can use it to terminate the server and exit its loop.But that never happens.


sasmaster avatar Jan 10 '18 12:01 sasmaster

That should work, it is unit tested. Would you try running the unit tests in your environment and report back? Call cmake with -DRPCLIB_BUILD_TESTS=ON.

sztomi avatar Jan 15 '18 15:01 sztomi

Can you point me to the place you test it in your tests?Maybe I do it wrong. I am not building your lib on Linux with CMake and it's a pain in the ass for me now to start reconfigure it.Thanks.

sasmaster avatar Jan 16 '18 14:01 sasmaster

It's here: https://github.com/rpclib/rpclib/blob/master/tests/rpc/this_server_test.cc#L28

sztomi avatar Jan 16 '18 14:01 sztomi

Well.I am not sure your test case is like my use case.

Here is what I do:

    ```

rpc::server srv(rpc::constants::DEFAULT_PORT); srv.bind("close", { rpc::this_server_t sserver = rpc::this_server(); sserver.stop(); return 1; }); srv.run();



And then I call from a client which is somewhere outside the program (using python rpc).
What happens is that src.run() doesn't exit from the blocking.


sasmaster avatar Jan 16 '18 15:01 sasmaster

Yeah, this sounds like a bug. I'll look into it.

sztomi avatar Jan 16 '18 15:01 sztomi

Hi. I am just checking,the bug is still open,right? Mike.

sasmaster avatar Feb 23 '18 15:02 sasmaster

Hi Mike,

Yes, sorry to say I didn't yet have time to look into it.

sztomi avatar Feb 26 '18 16:02 sztomi

Happens to me too, run() does not exit from blocking.

Working around it temporarily with a nasty hack.

            rpc::server rpc_server(port);
            std::atomic<bool> stop = false;
            ... bind callbacks
            rpc_server.async_run();
            do {
                std::this_thread::sleep_for(std::chrono::milliseconds(10));
            } while (!stop);

meshula avatar Mar 06 '18 21:03 meshula

Same problem here. I hope this bug will get fixed.

fhajji avatar Mar 31 '19 02:03 fhajji