Skip to content

Commit 3a88039

Browse files
authored
FIX: "bind: Address already in use" (#1028)
1 parent 34f9948 commit 3a88039

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/crow/http_server.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ namespace crow // NOTE: Already documented in "crow/app.h"
184184
void stop()
185185
{
186186
shutting_down_ = true; // Prevent the acceptor from taking new connections
187+
188+
// Explicitly close the acceptor
189+
// else asio will throw an exception (linux only), when trying to start server again:
190+
// what(): bind: Address already in use
191+
if (acceptor_.is_open())
192+
{
193+
CROW_LOG_INFO << "Closing acceptor. " << &acceptor_;
194+
acceptor_.close();
195+
}
196+
187197
for (auto& io_context : io_context_pool_)
188198
{
189199
if (io_context != nullptr)

0 commit comments

Comments
 (0)