**Describe what's wrong**

ClickHouse server fails to start with the following config:

```
<keeper_server>
    <tcp_port>2181</tcp_port>
    <server_id>1</server_id>
    <log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path>
    <snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
    <coordination_settings>
        <operation_timeout_ms>5000</operation_timeout_ms>
        <raft_logs_level>trace</raft_logs_level>
        <session_timeout_ms>10000</session_timeout_ms>
    </coordination_settings>
    <raft_configuration>
        <server>
            <can_become_leader>true</can_become_leader>
            <hostname>sas-n2pu34sjneaepg49.db.yandex.net</hostname>
            <id>1</id>
            <port>2888</port>
            <priority>1</priority>
            <start_as_follower>false</start_as_follower>
        </server>
    </raft_configuration>
</keeper_server>

<user_directories>
    <users_xml>
        <path>users.xml</path>
    </users_xml>
   <replicated>
       <zookeeper_path>/clickhouse/access/</zookeeper_path>
   </replicated>
</user_directories>
```

**Does it reproduce on recent release?**

Yes, it's reproducible on 22.1.3.7 and earlier versions (e.g. 21.11.10.1).

**Expected behavior**

ClickHouse server starts and works.

**Error message and/or stacktrace**

```
2022.01.25 10:58:06.320203 [ 47212 ] {} <Debug> ConfigReloader: Loading config '/etc/clickhouse-server/config.xml'
2022.01.25 10:58:06.321356 [ 47212 ] {} <Debug> ConfigReloader: Loaded config '/etc/clickhouse-server/config.xml', performing update on configuration
2022.01.25 10:58:06.323213 [ 47212 ] {} <Debug> ConfigReloader: Loaded config '/etc/clickhouse-server/config.xml', performed update on configuration
2022.01.25 10:58:06.326661 [ 47212 ] {} <Debug> ConfigReloader: Loading config '/etc/clickhouse-server/users.xml'
2022.01.25 10:58:06.327609 [ 47212 ] {} <Debug> ConfigReloader: Loaded config '/etc/clickhouse-server/users.xml', performing update on configuration
2022.01.25 10:58:06.328643 [ 47212 ] {} <Debug> ConfigReloader: Loaded config '/etc/clickhouse-server/users.xml', performed update on configuration
2022.01.25 10:58:06.328913 [ 47212 ] {} <Debug> Access(user directories): Added users.xml access storage 'users.xml', path: /etc/clickhouse-server/users.xml
2022.01.25 10:58:06.328935 [ 47212 ] {} <Debug> Access(user directories): Added replicated access storage 'replicated'
2022.01.25 10:58:06.330201 [ 47212 ] {} <Error> Application: Code: 999. Coordination::Exception: All connection tries failed while connecting to ZooKeeper. nodes: [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
 (Connection loss). (KEEPER_EXCEPTION), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xa82d07a in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
1. Coordination::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Coordination::Error, int) @ 0x14c1e7f5 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
2. Coordination::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Coordination::Error) @ 0x14c1eb36 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
3. Coordination::ZooKeeper::connect(std::__1::vector<Coordination::ZooKeeper::Node, std::__1::allocator<Coordination::ZooKeeper::Node> > const&, Poco::Timespan) @ 0x14c61a2f in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
4. Coordination::ZooKeeper::ZooKeeper(std::__1::vector<Coordination::ZooKeeper::Node, std::__1::allocator<Coordination::ZooKeeper::Node> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Poco::Timespan, Poco::Timespan, Poco::Timespan, std::__1::shared_ptr<DB::ZooKeeperLog>) @ 0x14c5fedf in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
5. zkutil::ZooKeeper::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x14c21101 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
6. zkutil::ZooKeeper::ZooKeeper(Poco::Util::AbstractConfiguration const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::ZooKeeperLog>) @ 0x14c2380d in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
7. void std::__1::allocator<zkutil::ZooKeeper>::construct<zkutil::ZooKeeper, Poco::Util::AbstractConfiguration const&, char const (&) [10], std::__1::shared_ptr<DB::ZooKeeperLog> >(zkutil::ZooKeeper*, Poco::Util::AbstractConfiguration const&, char const (&) [10], std::__1::shared_ptr<DB::ZooKeeperLog>&&) @ 0x134c769b in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
8. DB::Context::getZooKeeper() const @ 0x134a6ab6 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
9. DB::ReplicatedAccessStorage::initializeZookeeper() @ 0x12f2be52 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
10. DB::ReplicatedAccessStorage::startup() @ 0x12f2bd0f in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
11. DB::AccessControl::addReplicatedStorage(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<std::__1::shared_ptr<zkutil::ZooKeeper> ()> const&) @ 0x12e57aea in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
12. DB::AccessControl::addStoragesFromUserDirectoriesConfig(Poco::Util::AbstractConfiguration const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<std::__1::shared_ptr<zkutil::ZooKeeper> ()> const&) @ 0x12e5a8a5 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
13. DB::AccessControl::addStoragesFromMainConfig(Poco::Util::AbstractConfiguration const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<std::__1::shared_ptr<zkutil::ZooKeeper> ()> const&) @ 0x12e5be61 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
14. DB::Server::main(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0xa8b2ce9 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
15. Poco::Util::Application::run() @ 0x174746c6 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
16. DB::Server::run() @ 0xa8a8614 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
17. mainEntryClickHouseServer(int, char**) @ 0xa8a5bc7 in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
18. main @ 0xa82742a in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
19. __libc_start_main @ 0x21bf7 in /lib/x86_64-linux-gnu/libc-2.27.so
20. _start @ 0xa6ae3ee in /usr/lib/debug/.build-id/d1/1bc54a7fe20e44.debug
 (version 22.1.3.7 (official build))
2022.01.25 10:58:06.331876 [ 47212 ] {} <Error> Application: Coordination::Exception: All connection tries failed while connecting to ZooKeeper. nodes: [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
Poco::Exception. Code: 1000, e.code() = 111, Connection refused (version 22.1.3.7 (official build)), [2a02:6b8:c23:168b:0:1589:e034:1c8a]:2181
 (Connection loss)
2022.01.25 10:58:06.331966 [ 47212 ] {} <Information> Application: shutting down
2022.01.25 10:58:06.331972 [ 47212 ] {} <Debug> Application: Uninitializing subsystem: Logging Subsystem
2022.01.25 10:58:06.332029 [ 47213 ] {} <Information> BaseDaemon: Stop SignalListener thread
2022.01.25 10:58:06.362269 [ 47211 ] {} <Information> Application: Child process exited normally with code 70.
```

extern const Metric MaxDDLEntryID;
    extern const Metric MaxPushedDDLEntryID;
}
namespace ProfileEvents
{
    extern const Event MainConfigLoads;
}
namespace fs = std::filesystem;
#if USE_JEMALLOC
static bool jemallocOptionEnabled(const char *name)
{
    bool value;
    size_t size = sizeof(value);
    if (mallctl(name, reinterpret_cast<void *>(&value), &size,  nullptr,  0))
        throw Poco::SystemException("mallctl() failed");
    return value;
}
#else
static bool jemallocOptionEnabled(const char *) { return 0; }
#endif
int mainEntryClickHouseServer(int argc, char ** argv)
{
    DB::Server app;
    if (jemallocOptionEnabled("opt.background_thread"))
    {
        LOG_ERROR(&app.logger(),
            "jemalloc.background_thread was requested, "
            "however ClickHouse uses percpu_arena and background_thread most likely will not give any benefits, "
            "and also background_thread is not compatible with ClickHouse watchdog "
            "(that can be disabled with CLICKHOUSE_WATCHDOG_ENABLE=0)");