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 execute_future not working with tokio::spawn #166

Merged
merged 2 commits into from
Nov 13, 2023

Conversation

probakowski
Copy link
Contributor

In some cases (e.g. when using async IO, like TCP connection) resolving DNS queries for KDC will block when used in tokio::spawn-ed task. AFAICT this happens because we block thread that is used by IO and timers.
This change fixes that with use block_in_place so the thread we're on will be marked by tokio as blocked and other task will be moved to the new one.

@CBenoit CBenoit self-requested a review September 25, 2023 20:22
@CBenoit CBenoit self-assigned this Sep 25, 2023
Cargo.toml Outdated
@@ -63,7 +63,7 @@ num-bigint-dig = "0.8"
tracing = "0.1"
rustls = { version = "0.21", features = ["dangerous_configuration"], optional = true }
zeroize = { version = "1.6", features = ["zeroize_derive"] }
tokio = { version = "1.32", features = ["time", "rt"], optional = true }
tokio = { version = "1.32", features = ["time", "rt", "rt-multi-thread"], optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to enable the "rt-multi-thread" feature for tokio?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tokio::block_in_place is guarded by check for rt-multi-thread feature. We can either enable it here or add another feature in sspi to and add it there (with cfg guard in code)

Copy link
Member

Choose a reason for hiding this comment

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

Oh okay! In that case, I think it’s good as-is, let’s not add more complexity to this. Longer term, I also have a plan for removing the dependency to tokio completely and leave the user spawn a task in their runtime directly.

dns_resolver = ["dep:trust-dns-resolver", "dep:tokio"]
dns_resolver = ["dep:trust-dns-resolver", "dep:tokio", "tokio/rt-multi-thread"]
Copy link
Member

Choose a reason for hiding this comment

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

This change is good, thank you 👍

tokio = { version = "1.32", features = ["time", "rt"] }
tokio = { version = "1.32", features = ["time", "rt", "rt-multi-thread"] }
Copy link
Member

@CBenoit CBenoit Nov 13, 2023

Choose a reason for hiding this comment

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

Since the rt-multi-thread feature is now implied by dns_resolver, you can probably remove it from here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#[cfg(any(feature = "dns_resolver", target_os = "macos", target_os = "ios"))]<- you have to enable it for either dns_resolver or macos/ios, so it's required in both places

Copy link
Member

Choose a reason for hiding this comment

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

Oh, okay! 👍

Copy link
Member

Choose a reason for hiding this comment

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

It’s probably redundant, but it’s not on you, I’ll merge as-is

@CBenoit CBenoit enabled auto-merge (squash) November 13, 2023 19:42
Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

Thank you!

@CBenoit CBenoit merged commit d54bdfc into Devolutions:master Nov 13, 2023
40 checks passed
@probakowski probakowski deleted the probakowski/fix-dns-check branch November 13, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants