Skip to content

Commit

Permalink
Fix DNS resolve mutex locks
Browse files Browse the repository at this point in the history
This fixes godotengine#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.
  • Loading branch information
sarchar committed Jun 3, 2021
1 parent 4e52b84 commit 48f7e06
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions core/io/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -129,15 +128,14 @@ 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)) {
_resolve_hostname(resolver->cache[key], p_hostname, p_type);
}

List<IPAddress> res = resolver->cache[key];
resolver->mutex.unlock();

Array result;
for (int i = 0; i < res.size(); ++i) {
Expand Down Expand Up @@ -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();
Expand All @@ -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<IPAddress> 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];
Expand All @@ -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<IPAddress> res = resolver->queue[p_id].response;

resolver->mutex.unlock();

Array result;
for (int i = 0; i < res.size(); ++i) {
if (res[i].is_valid()) {
Expand Down

0 comments on commit 48f7e06

Please sign in to comment.