Giter VIP home page Giter VIP logo

Comments (8)

marcindodo avatar marcindodo commented on May 3, 2024 5

@jeffsyang
sorry for delay, it is working for me:

volatile int state = 1;

std::cout << "Starting listener on port " << addr.port() << std::endl;
server->serveThreaded();

while(state)
    sleep(1);

std::cout << "Shutting down server" << std::endl;
server->shutdown();

and in another function I change flag state to 0 and then server shutdown..

from pistache.

dennisjenkins75 avatar dennisjenkins75 commented on May 3, 2024 3

The SIGINT handler does not work. There is a more recent open bug to track fixing it, but it has not received much love lately. Most of us run our pistache with "serveThreaded()". "shutdown()" works fine with "serveThreaded()".

See issue #221.

from pistache.

marcindodo avatar marcindodo commented on May 3, 2024

I also needed graceful shutdown, maybe instead of serve() use serveThreaded() and then call shutdown() only on request, flag or signal handler. It seems to me that for me it's working properly.

from pistache.

jeffsyang avatar jeffsyang commented on May 3, 2024

@marcindodo That's what I was thinking as well. That said, were you able to start only one Endpoint with serveThreaded()? When I do so, it continues executing code after serveThreaded() and ultimately, terminates. Only serve() seem to keep the Endpoint up until manual termination...

Just implemented it using this example as a base. Although httpEndpoint->shutdown() does get called successfully when calling /shutdown, it does not stop the server. Incoming requests to the Endpoint just hang and don't receive a response since the Endpoint had been stopped.

How did you get serveThreaded() and and /shutdown working?

from pistache.

xoac avatar xoac commented on May 3, 2024

It works for me too. @jeffsyang if this satisfy you can close this issue.

from pistache.

jeffsyang avatar jeffsyang commented on May 3, 2024

Thanks guys!

from pistache.

MasterGroosha avatar MasterGroosha commented on May 3, 2024

server->serveThreaded();

However, if you take code from examples on github:

auto server = std::make_shared<Http::Endpoint>(addr);
auto opts = Http::Endpoint::options()
        .threads(thr)
        .flags(Tcp::Options::InstallSignalHandler);
server->init(opts);
server->setHandler(Http::make_handler<MyHandler>());
server->serve();
std::cout << "Shutdowning server" << std::endl;
server->shutdown();

Then you won't be able to stop server with Ctrl+C. With serveThreaded() it works fine.

from pistache.

Fabio3rs avatar Fabio3rs commented on May 3, 2024

I am using serverThreaded() and if I use shutdown() while a client request is running, the server waits the route function return to close de process (That is ok),
The client stays connected until the process finishes, but does not receive the response.

I am testing with std::this_thread::sleep_for(std::chrono::seconds(20)); to simulate a long request

Chrome says ERR_CONNECTION_REFUSED
Thunder Client (VSCode plugin) says Connection was forcibly closed by a peer. Size 0 bytes

I am using Linux Mint 20 with kernel 5.11.0-25-generic. Compiled the Pistache with clang
clang --version clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

I think the thread that handles the responses to the client is being stoped before the route function returns.

from pistache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.