From 48f7e06976ac31a6f242d8bf26f8f479f9dc6fa4 Mon Sep 17 00:00:00 2001 From: Chuck Date: Thu, 3 Jun 2021 11:46:18 +0700 Subject: [PATCH] Fix DNS resolve mutex locks This fixes #49261, which was happening because of a deadlock in the resolver mutex. There was leftover old mutex code and it's all be converted to new MutexLock class now. --- core/io/ip.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/io/ip.cpp b/core/io/ip.cpp index de37ba87dd76..001b1c47574b 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -118,7 +118,6 @@ IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { _resolve_hostname(res, p_hostname, p_type); resolver->cache[key] = res; } - resolver->mutex.unlock(); for (int i = 0; i < res.size(); ++i) { if (res[i].is_valid()) { @@ -129,7 +128,7 @@ IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { } Array IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { - resolver->mutex.lock(); + MutexLock lock(resolver->mutex); String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); if (!resolver->cache.has(key)) { @@ -137,7 +136,6 @@ Array IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { } List res = resolver->cache[key]; - resolver->mutex.unlock(); Array result; for (int i = 0; i < res.size(); ++i) { @@ -184,7 +182,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { if (resolver->queue[p_id].status.get() == IP::RESOLVER_STATUS_NONE) { ERR_PRINT("Condition status == IP::RESOLVER_STATUS_NONE"); - resolver->mutex.unlock(); return IP::RESOLVER_STATUS_NONE; } return resolver->queue[p_id].status.get(); @@ -197,14 +194,11 @@ IPAddress IP::get_resolve_item_address(ResolverID p_id) const { if (resolver->queue[p_id].status.get() != IP::RESOLVER_STATUS_DONE) { ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet."); - resolver->mutex.unlock(); return IPAddress(); } List res = resolver->queue[p_id].response; - resolver->mutex.unlock(); - for (int i = 0; i < res.size(); ++i) { if (res[i].is_valid()) { return res[i]; @@ -215,19 +209,15 @@ IPAddress IP::get_resolve_item_address(ResolverID p_id) const { Array IP::get_resolve_item_addresses(ResolverID p_id) const { ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, Array()); - - resolver->mutex.lock(); + MutexLock lock(resolver->mutex); if (resolver->queue[p_id].status.get() != IP::RESOLVER_STATUS_DONE) { ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet."); - resolver->mutex.unlock(); return Array(); } List res = resolver->queue[p_id].response; - resolver->mutex.unlock(); - Array result; for (int i = 0; i < res.size(); ++i) { if (res[i].is_valid()) {