From 8ad1bd1928728bd1a7d9888f337031c493615a46 Mon Sep 17 00:00:00 2001 From: Ilya Bizyaev Date: Sun, 14 Jul 2024 18:42:30 +0200 Subject: [PATCH 1/3] Bump deps of webhook-axum Otherwise some changes in axum's Router interface prevent teloxide's webhook support from being used with up-to-date axum. --- crates/teloxide/Cargo.toml | 6 +++--- crates/teloxide/src/update_listeners/webhooks/axum.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/teloxide/Cargo.toml b/crates/teloxide/Cargo.toml index ef204d2c..48116b65 100644 --- a/crates/teloxide/Cargo.toml +++ b/crates/teloxide/Cargo.toml @@ -112,9 +112,9 @@ sqlx = { version = "0.7.3", optional = true, default-features = false, features redis = { version = "0.24", features = ["tokio-comp"], optional = true } serde_cbor = { version = "0.11", optional = true } bincode = { version = "1.3", optional = true } -axum = { version = "0.6.0", optional = true } -tower = { version = "0.4.12", optional = true } -tower-http = { version = "0.3.4", features = ["trace"], optional = true } +axum = { version = "0.7.0", optional = true } +tower = { version = "0.4.13", optional = true } +tower-http = { version = "0.5.2", features = ["trace"], optional = true } rand = { version = "0.8.5", optional = true } # HACK: ahash 0.8.7 bumped MSRV to 1.72, to keep MVSR 1.68 we need to depend on an older version. diff --git a/crates/teloxide/src/update_listeners/webhooks/axum.rs b/crates/teloxide/src/update_listeners/webhooks/axum.rs index 2a915a55..9cd019af 100644 --- a/crates/teloxide/src/update_listeners/webhooks/axum.rs +++ b/crates/teloxide/src/update_listeners/webhooks/axum.rs @@ -47,13 +47,13 @@ where ::DeleteWebhook: Send, { let Options { address, .. } = options; + let tcp_listener = tokio::net::TcpListener::bind(address).await.unwrap(); let (mut update_listener, stop_flag, app) = axum_to_router(bot, options).await?; let stop_token = update_listener.stop_token(); tokio::spawn(async move { - axum::Server::bind(&address) - .serve(app.into_make_service()) + axum::serve(tcp_listener, app) .with_graceful_shutdown(stop_flag) .await .map_err(|err| { @@ -90,7 +90,7 @@ where /// [`delete_webhook`]: crate::payloads::DeleteWebhook /// [`stop`]: crate::stop::StopToken::stop /// [`options.address`]: Options::address -/// [`with_graceful_shutdown`]: axum::Server::with_graceful_shutdown +/// [`with_graceful_shutdown`]: axum::serve::Serve::with_graceful_shutdown /// /// ## Returns /// From 7d5253a3f17f03065a863532e407330b76646abd Mon Sep 17 00:00:00 2001 From: Ilya Bizyaev Date: Sun, 14 Jul 2024 19:48:26 +0200 Subject: [PATCH 2/3] Improve error handling --- crates/teloxide/src/update_listeners/webhooks/axum.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/teloxide/src/update_listeners/webhooks/axum.rs b/crates/teloxide/src/update_listeners/webhooks/axum.rs index 9cd019af..784848dd 100644 --- a/crates/teloxide/src/update_listeners/webhooks/axum.rs +++ b/crates/teloxide/src/update_listeners/webhooks/axum.rs @@ -47,12 +47,18 @@ where ::DeleteWebhook: Send, { let Options { address, .. } = options; - let tcp_listener = tokio::net::TcpListener::bind(address).await.unwrap(); let (mut update_listener, stop_flag, app) = axum_to_router(bot, options).await?; let stop_token = update_listener.stop_token(); tokio::spawn(async move { + let tcp_listener = tokio::net::TcpListener::bind(address) + .await + .map_err(|err| { + stop_token.stop(); + err + }) + .expect("Couldn't bind to the address"); axum::serve(tcp_listener, app) .with_graceful_shutdown(stop_flag) .await From 234bfb972053aac296699718cacc05d94fc86088 Mon Sep 17 00:00:00 2001 From: Ilya Bizyaev Date: Sun, 14 Jul 2024 20:57:19 +0200 Subject: [PATCH 3/3] Add a changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4a82ef4..366d254b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sqlx version was bumped from `0.6` to `0.7.3`([PR 995](https://github.com/teloxide/teloxide/pull/995)) - Feature `sqlite-storage` was renamed to `sqlite-storage-nativetls`([PR 995](https://github.com/teloxide/teloxide/pull/995)) - MSRV (Minimal Supported Rust Version) was bumped from `1.68.0` to `1.70.0` ([PR 996][https://github.com/teloxide/teloxide/pull/996]) +- `axum` was bumped to `0.7`, along with related libraries used for webhooks ([PR 1093][https://github.com/teloxide/teloxide/pull/1093]) ### Removed