Skip to content

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Jan 29, 2026

Detect and ignore Kubernetes-injected SQLPAGE_PORT URI values to prevent crashes during deployment.

When deploying to Kubernetes, if a service named sqlpage exists, Kubernetes automatically injects an environment variable like SQLPAGE_PORT=tcp://10.0.0.11:8080. This URI format clashes with SQLPage's expectation of an integer port, causing the application to crash. This change adds a custom deserializer for the port configuration that detects this URI format, logs a warning, and ignores the value, allowing SQLPage to start correctly using its default port or other configured port.


Open in Cursor Open in Web

…t variables

Co-authored-by: contact <contact@ophir.dev>
@cursor
Copy link

cursor bot commented Jan 29, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Copy link
Collaborator Author

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

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

@cursoragent do not deserialize the port as json

Comment on lines 430 to 435
let v: Option<serde_json::Value> = Deserialize::deserialize(deserializer)?;
match v {
Some(serde_json::Value::Number(n)) => {
if let Some(port) = n.as_u64() {
if port <= 65535 {
Ok(Some(port as u16))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you can just try to deserialize as u16 directly

Comment on lines 443 to 444
Some(serde_json::Value::String(s)) => {
if let Ok(port) = s.parse::<u16>() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do not reparse number

@cursor
Copy link

cursor bot commented Jan 29, 2026

I have updated deserialize_port to use a custom serde::de::Visitor instead of deserializing into serde_json::Value. This avoids the intermediate JSON representation and directly handles integers and strings, addressing the feedback to not deserialize the port as JSON.

The implementation now:

  1. Defines a PortVisitor struct.
  2. Implements visit_u64 and visit_i64 to handle numeric port values directly.
  3. Implements visit_str to handle string port values, including the Kubernetes tcp:// format check.
  4. Handles Option unwrapping via visit_some, visit_none, and visit_unit.

This change is cleaner and more efficient as it avoids the overhead of the serde_json::Value enum.

Open in Cursor Open in Web

@lovasoa
Copy link
Collaborator Author

lovasoa commented Jan 29, 2026

@cursoragent cargo clippy

error: variables can be used directly in the `format!` string
   --> src/app_config.rs:460:17
    |
460 |                 log::warn!("Ignoring invalid SQLPAGE_PORT value from Kubernetes: {}", v);
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#uninlined_format_args
note: the lint level is defined here
   --> src/lib.rs:1:9
    |
  1 | #![deny(clippy::pedantic)]
    |         ^^^^^^^^^^^^^^^^
    = note: `#[deny(clippy::uninlined_format_args)]` implied by `#[deny(clippy::pedantic)]`
help: change this to
    |
460 -                 log::warn!("Ignoring invalid SQLPAGE_PORT value from Kubernetes: {}", v);
460 +                 log::warn!("Ignoring invalid SQLPAGE_PORT value from Kubernetes: {v}");
    |

error: variables can be used directly in the `format!` string
   --> src/app_config.rs:463:31
    |
463 |                 Err(E::custom(format!("Invalid port number: {}", v)))
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#uninlined_format_args
help: change this to
    |
463 -                 Err(E::custom(format!("Invalid port number: {}", v)))
463 +                 Err(E::custom(format!("Invalid port number: {v}")))
    |

@cursor
Copy link

cursor bot commented Jan 29, 2026

I have fixed the clippy::uninlined_format_args warnings in src/app_config.rs by inlining the v variable into the format strings.

// Before
log::warn!("Ignoring invalid SQLPAGE_PORT value from Kubernetes: {}", v);
Err(E::custom(format!("Invalid port number: {}", v)))

// After
log::warn!("Ignoring invalid SQLPAGE_PORT value from Kubernetes: {v}");
Err(E::custom(format!("Invalid port number: {v}")))

Open in Cursor Open in Web

Co-authored-by: contact <contact@ophir.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants