Comments (8)
@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.
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.
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.
@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.
It works for me too. @jeffsyang if this satisfy you can close this issue.
from pistache.
Thanks guys!
from pistache.
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.
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)
- [BUG] ResponseWriter::setCompression() chokes on identity encoding
- [BUG] Fails to fetch build dependencies in autopkgtest HOT 7
- [BUG] All PPA builds failing due to missing zlib headers
- [BUG] New compression code fails to build on armhf HOT 5
- decode uri
- Complete BSD support HOT 4
- "Stack smashing detected" error in ubuntu docker container HOT 17
- New release to conan HOT 1
- keep alive timeout doesn't add to response header
- Pistache very poor performance when POST size exceeds `Endpoint::options().maxRequestSize()`, and `maxRequestSize` is large. HOT 4
- Out of bound read in std::strtol while parsing HTTP requests HOT 4
- Endpoint::Options::backlog_ is not used HOT 2
- What's up with the logging? HOT 3
- [FEATURE REQUEST] Add support for zstd compression
- ci: coverage fails on debian:testing runners HOT 3
- Cant stream MJPEG with multipart/x-mixed-replace HOT 2
- releasing / tagging HOT 1
- Pistacheio support for QNX
- “stack smashing detected” error when processing Get requests via generated-cpp-pistache-server HOT 6
- failed to build example HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pistache.