dfleury2 / beauty

A Simple C++ Http server/client above Boost.Beast
MIT License
188 stars 23 forks source link

Don't accept more connections if accept fails #12

Open p12tic opened 2 years ago

p12tic commented 2 years ago

This fixes infinite loop in case application uses an external io_context in which case _app.stop() does nothing.

dfleury2 commented 2 years ago

Hi, what's happening is internal io_context is used ? the do_accept will not be called and the acceptor will not be registered to the io_context ?

Using the added unit tests, I am not sure how I can simulate a failure on on_accept, or doing it using the examples.

p12tic commented 2 years ago

You're right. I will create a failing unit test and get back.

MiSo1289 commented 3 months ago

Hi @dfleury2 - this issue still occurs on the latest version. From what I can see, it's caused by the acceptor handling the accept error by calling app.stop() - but this method does nothing if user's io context is used. This patch would at least alleviate the issue by not causing infinite spam in the console, only logging the error once; ideally, I would prefer if the error from bind() call in the acceptor could be propagated to the user's thread calling server.listen() as an exception. Should I try to submit such a patch?

dfleury2 commented 3 months ago

Hi, yes of course. The use of an external io_context was added later, and it's not the prefered way to use beauty. If you succeed this issue, you are welcome.