Skip to content

Commit

Permalink
pin fewer futures, but add linter to make sure we don't backslide (#177)
Browse files Browse the repository at this point in the history
* pin fewer futures, but add linter to make sure we don't backslide

* less stack, more heap!
  • Loading branch information
mhils authored Sep 5, 2024
1 parent 1c3c0a2 commit 2aa7ebb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ repository = "https://github.com/mitmproxy/mitmproxy-rs"
edition = "2021"
rust-version = "1.80" # MSRV

[workspace.lints.clippy]
large_futures = "deny"

[package]
name = "mitmproxy"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions mitmproxy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ edition.workspace = true
rust-version.workspace = true
publish.workspace = true

[lints]
workspace = true

[lib]
name = "mitmproxy_rs"
crate-type = ["lib", "cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy-rs/src/server/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl Server {

// spawn tasks
let mut tasks = JoinSet::new();
tasks.spawn(Box::pin(async move { packet_source_task.run().await }));
tasks.spawn(Box::pin(async move { py_task.run().await }));
tasks.spawn(async move { packet_source_task.run().await });
tasks.spawn(async move { py_task.run().await });

let (shutdown_done_tx, shutdown_done_rx) = broadcast::channel(1);
tokio::spawn(shutdown_task(tasks, shutdown_done_tx));
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy-rs/src/udp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct UdpClientTask {

impl UdpClientTask {
pub async fn run(mut self) -> Result<()> {
let mut udp_buf = [0; MAX_PACKET_SIZE];
let mut udp_buf = vec![0; MAX_PACKET_SIZE];

// this here isn't perfect because we block the entire transport_commands_rx channel if we
// cannot send (so we also block receiving new packets), but that's hopefully good enough.
Expand All @@ -114,7 +114,7 @@ impl UdpClientTask {
loop {
tokio::select! {
// wait for transport_events_tx channel capacity...
r = self.socket.recv(&mut udp_buf), if packet_tx.is_some() => {
r = self.socket.recv(udp_buf.as_mut_slice()), if packet_tx.is_some() => {
if remote_host_closed_conn(&r) {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions mitmproxy-windows/redirector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ edition.workspace = true
rust-version.workspace = true
publish.workspace = true

[lints]
workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(windows)'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/network/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn add_network_layer(
transport_commands_rx,
shutdown,
)?;
let h = tokio::spawn(Box::pin(async move { task.run().await }));
let h = tokio::spawn(async move { task.run().await });
Ok((h, network_events_tx, network_commands_rx))
}

Expand Down
3 changes: 3 additions & 0 deletions wireguard-test-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ edition.workspace = true
rust-version.workspace = true
publish.workspace = true

[lints]
workspace = true

[dependencies]
anyhow = "1.0.86"
data-encoding = "2.6.0"
Expand Down

0 comments on commit 2aa7ebb

Please sign in to comment.