This allows starting and stopping separately each protocol server
without restarting ClickHouse.
This also allows adding or removing `listen_host` entries, which
start and stops servers for all enabled ports.
When stopping a server, the listening socket is immediately closed
(and available for another server).
Protocols with persistent connections try to wait for any currently
running query to finish before closing the connection, but idle
connection are closed quickly (depending on how often the protocol
is polled).
An extra ProfileEvent is added, `MainConfigLoads`, it is
incremented every time the configuration is reloaded. This helps
when trying to assess whether the new configuration was applied.
Otherwise you may hit internal assertion when client goes away:
clickhouse-server: ./src/Server/HTTP/HTMLForm.cpp:245: bool DB::HTMLForm::MultipartReadBuffer::skipToNextBoundary(): Assertion `boundary_hit' failed.
Fixes: 02151_http_s_structure_set_eof
To handle cancel_http_readonly_queries_on_client_close=true context
attaches progress callback with holding a copy of the current context,
and this creates recursive context reference and so shared_ptr will be
never released, [1] contains simplest example.
One example of a memory leak, external tables passed with HTTP query
(s_structure + file upload), since they are stored in the context, and
can occupate enough memory to make it visible to user.
Note, that the lifetime of the Context should be fine, since callback
can be called only when query is executed.
[1]: Example of recursive reference
```c
#include <memory>
#include <functional>
#include <cassert>
bool released = true;
class Context : public std::enable_shared_from_this<Context>
{
using Func = std::function<void()>;
Func func;
public:
Context() { released = false; }
~Context() { released = true; }
Context(const Context & context) = delete;
void addCallback(Func func_)
{
func = func_;
}
};
int main()
{
{
auto context = std::make_shared<Context>();
context->addCallback([context]() {});
}
assert(released == true);
}
```