**Describe the situation**

```
ip-172-31-22-38.eu-central-1.compute.internal :) TRUNCATE wikistat

TRUNCATE TABLE wikistat

Query id: 3a045ee6-201c-4551-9bc1-3cda53376ec2


0 rows in set. Elapsed: 120.008 sec. 

Received exception from server (version 22.2.1):
Code: 473. DB::Exception: Received from localhost:9000. DB::Exception: WRITE locking attempt on "default.wikistat" has timed out! (120000ms) Possible deadlock avoided. Client should retry.. (DEADLOCK_AVOIDED)

ip-172-31-22-38.eu-central-1.compute.internal :) TRUNCATE wikistat

TRUNCATE TABLE wikistat

Query id: 4fae1b33-c9cb-45de-8ff2-140d9cba3aa2

Ok.

0 rows in set. Elapsed: 31.647 sec. 

ip-172-31-22-38.eu-central-1.compute.internal :)
```

```
┌─arrayJoin(arrayMap(lambda(tuple(x), demangle(addressToSymbol(x))), trace))─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                                                                                                                                            │
│ std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >)                            │
│ DB::RWLockImpl::getLock(DB::RWLockImpl::Type, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > const&)                                     │
│ DB::IStorage::tryLockTimed(std::__1::shared_ptr<DB::RWLockImpl> const&, DB::RWLockImpl::Type, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > const&) const │
│ DB::IStorage::lockExclusively(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > const&)                                                     │
│ DB::InterpreterDropQuery::executeToTableImpl(std::__1::shared_ptr<DB::Context const>, DB::ASTDropQuery&, std::__1::shared_ptr<DB::IDatabase>&, StrongTypedef<wide::integer<128ul, unsigned int>, DB::UUIDTag>&)                                            │
│ DB::InterpreterDropQuery::executeToTable(DB::ASTDropQuery&)                                                                                                                                                                                                │
│ DB::InterpreterDropQuery::execute()                                                                                                                                                                                                                        │
│ DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*)                                                                                                                   │
│ DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum)                                                                    │
│ DB::TCPHandler::runImpl()                                                                                                                                                                                                                                  │
│ DB::TCPHandler::run()                                                                                                                                                                                                                                      │
│ Poco::Net::TCPServerConnection::start()                                                                                                                                                                                                                    │
│ Poco::Net::TCPServerDispatcher::run()                                                                                                                                                                                                                      │
│ Poco::PooledThread::run()                                                                                                                                                                                                                                  │
│ Poco::ThreadImpl::runnableEntry(void*)
```
bool is_drop_or_detach_database = !query_ptr->as<ASTDropQuery>()->table;
        bool is_replicated_ddl_query = typeid_cast<DatabaseReplicated *>(database.get()) &&
                                       !context_->getClientInfo().is_replicated_database_internal &&
                                       !is_drop_or_detach_database;
        AccessFlags drop_storage;
        if (table->isView())
            drop_storage = AccessType::DROP_VIEW;
        else if (table->isDictionary())
            drop_storage = AccessType::DROP_DICTIONARY;
        else
            drop_storage = AccessType::DROP_TABLE;
        if (is_replicated_ddl_query)
        {
            if (query.kind == ASTDropQuery::Kind::Detach)
                context_->checkAccess(drop_storage, table_id);
            else if (query.kind == ASTDropQuery::Kind::Truncate)
                context_->checkAccess(AccessType::TRUNCATE, table_id);
            else if (query.kind == ASTDropQuery::Kind::Drop)
                context_->checkAccess(drop_storage, table_id);
            ddl_guard->releaseTableLock();
            table.reset();
            return typeid_cast<DatabaseReplicated *>(database.get())->tryEnqueueReplicatedDDL(query.clone(), context_);
        }
        if (query.kind == ASTDropQuery::Kind::Detach)
        {
            context_->checkAccess(drop_storage, table_id);
            if (table->isDictionary())
            {
                
                if (!query.is_dictionary)