Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DNS resolve mutex locks #49269

Merged
merged 1 commit into from
Jun 3, 2021
Merged

Conversation

sarchar
Copy link
Contributor

@sarchar sarchar commented Jun 3, 2021

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.

@sarchar sarchar requested a review from a team as a code owner June 3, 2021 04:47
@akien-mga akien-mga added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:dotnet topic:network labels Jun 3, 2021
@akien-mga akien-mga added this to the 4.0 milestone Jun 3, 2021
@akien-mga
Copy link
Member

There's still three more calls to unlock() in early returns, shouldn't they be removed?

@sarchar
Copy link
Contributor Author

sarchar commented Jun 3, 2021

There's still three more calls to unlock() in early returns, shouldn't they be removed?

Yeah, I think they probably should be, but they were in the code before my original PR and so I was skeptical to touch them in case someone else added them for some actual purpose.

Should I remove them too? They seem to all be in error condition branches that probably never get hit, which is why they've not been a problem.

@akien-mga
Copy link
Member

Right, this might need checking by @RandomShaper who implemented the Mutex changes in 18fbdbb. In this commit he removed most ->unlock() calls but he kept two of them as .unlock(), and then your PR added a third one following the same pattern.

@sarchar
Copy link
Contributor Author

sarchar commented Jun 3, 2021

Right, this might need checking by @RandomShaper who implemented the Mutex changes in 18fbdbb. In this commit he removed most ->unlock() calls but he kept two of them as .unlock(), and then your PR added a third one following the same pattern.

OK, so wait and see what @RandomShaper says. I can easily remove them if he says they're not needed.

Copy link
Member

@RandomShaper RandomShaper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I took things out of balance by adding the RAII (MutexLock) style and forgetting to remove some of the explicit unlocks.

By the way, this PR makes the same mistake. 😃 Please remove the explicit unlocks inside the ifs where you have switched to the scoped lock style, and please do so also in get_resolve_item_status(), where I forgot myself.

Furthermore, I don't think it will actually impact performance, but it's even better to enclose each MutexLock declaration along with the code it protects in a scope so the lock is released earlier instead of at the end of the function. I don't know if the original intent of the code regarding the early-unlock was optimization or just to avoid writing the unlock call many times, but, in any case, it won't harm.

UPDATE: To elaborate, I didn't have a strong reason to keep the explicit lock/unlock or fully switch to the scoped style. I just decided on a per case basis judging which would be more readable, but now I think it's better to use MutexLock everywhere, at least in this class, for consistency.

@sarchar
Copy link
Contributor Author

sarchar commented Jun 3, 2021

By the way, this PR makes the same mistake. 😃 Please remove the explicit unlocks inside the ifs where you have switched to the scoped lock style, and please do so also in get_resolve_item_status(), where I forgot myself.

In that case, I'll remove the extra unlock() calls and push an update in 10 minutes.

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.
@akien-mga akien-mga merged commit a867c5a into godotengine:master Jun 3, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subsequent requests in HTTPRequest don't resolve after #49026
3 participants