Repository: rustls/rustls (language: rust)

Issue:
Make UserCanceled Alert Warning not be tracing::warn!
**Checklist**
* [x] I've searched the issue tracker for similar bugs.

**Describe the bug**
A clear and concise description of what the bug is.

When running our server for hours we get warning logs from rustls

```
{"timestamp":"2024-10-26T14:36:31.330816392+00:00","level":"WARN","fields":{"message":"TLS alert warning received: AlertMessagePayload { level: Warning, description: UserCanceled }","log.target":"rustls::common_state","log.module_path":"rustls::common_state","log.file":"/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.23.14/src/common_state.rs","log.line":519},"target":"rustls::common_state","filename":/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.23.14/src/common_state.rs","line_number":519}
```

https://github.com/rustls/rustls/blob/121d813ca87fe881881cb29b04471af642131a55/rustls/src/common_state.rs#L527

**To Reproduce**

Not sure.

**Applicable Version(s)**
A list of versions and platforms you've tested with.

v0.23.14

**Expected behavior**

We are unsure if these warnings are meaningful? Is there something on our end that we should fix? How do we know if this is an issue or if we should just silence them?  

**Additional context**
-_-


Discussion / hints:

Fix patch:
diff --git a/rustls/src/common_state.rs b/rustls/src/common_state.rs
index b4af2acdaa0..9b9ab3f7f4c 100644
--- a/rustls/src/common_state.rs
+++ b/rustls/src/common_state.rs
@@ -523,10 +523,15 @@ impl CommonState {
                 .received_warning_alert()?;
             if self.is_tls13() && alert.description != AlertDescription::UserCanceled {
                 return Err(self.send_fatal_alert(AlertDescription::DecodeError, err));
-            } else {
-                warn!("TLS alert warning received: {:?}", alert);
-                return Ok(());
             }
+
+            // Some implementations send pointless `user_canceled` alerts, don't log them
+            // in release mode (https://bugs.openjdk.org/browse/JDK-8323517).
+            if alert.description != AlertDescription::UserCanceled || cfg!(debug_assertions) {
+                warn!("TLS alert warning received: {alert:?}");
+            }
+
+            return Ok(());
         }
 
         Err(err)


Test patch: