Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Unable to recover http_server_t after encountering problems on open #84

Closed prince-chrismc closed 4 years ago

prince-chrismc commented 4 years ago

I am trying detect errors when starting and restart the server in an attempt to recover. I seem to have hit a road block in my endeavor, and I am not sure if my use case far fetched or there is a bug.

Regardless, I would greatly appreciate some feedback on this issue.

By calling https://github.com/Stiffstream/restinio/blob/6934bd5a8ad707eb6a04894ec3bb198a39f447d9/dev/restinio/http_server.hpp#L294-L302 I do in fact receive all the exceptions from asio that I am anticipating thanks to the bind call https://github.com/Stiffstream/restinio/blob/6934bd5a8ad707eb6a04894ec3bb198a39f447d9/dev/restinio/impl/acceptor.hpp#L232-L242

However when the recovery attempt is made, the acceptor is still seen as open and when local_endpoint() is called it throws an exception. https://github.com/Stiffstream/restinio/blob/6934bd5a8ad707eb6a04894ec3bb198a39f447d9/dev/restinio/impl/acceptor.hpp#L204-L211

Now, I have made sure to place a call to https://github.com/Stiffstream/restinio/blob/6934bd5a8ad707eb6a04894ec3bb198a39f447d9/dev/restinio/http_server.hpp#L348-L357 but this does not pass the if() condition since m_running_state = running_state_t::running is only set after a successful call to m_acceptor->open();

It seems to me there is a missing intermediate step starting where I could close the server from. I should be able to provide some sample code if that is require to reproduce the issue.

If this is not an intended use case, I am able to work around the problem by destroying the http_server_t and making a new router and server.

prince-chrismc commented 4 years ago

<3 thank you so much