Skip to content

fix(async-nats): add empty subject check #1402

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hysyeah
Copy link

@hysyeah hysyeah commented Apr 26, 2025

Background
The send_publish function previously did not validate for empty subject strings.
This oversight allowed empty subjects to be processed, which caused nats-server to incorrectly route request payloads to the respond box, then resulting in JSON deserialization failures.
like that:
Error: Error { kind: Other, source: Some(Error("data did not match any variant of untagged enum Response", line: 0, column: 0)) }

what this pr do
This PR adds a validation check for empty subjects in the send_publish, immediately returning an error when a subject is empty.

@Jarema
Copy link
Member

Jarema commented May 8, 2025

Hey. Thanks for the PR. However, can you elaborate or show example how empty subject was affecting request/response patterns and routing?

Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

This should be validated on Core Nats level, with new error kind.

@hysyeah
Copy link
Author

hysyeah commented May 15, 2025

Hey. Thanks for the PR. However, can you elaborate or show example how empty subject was affecting request/response patterns and routing?

    let publish_result = js.publish(
        "".to_string(),
        serde_json::to_string(&event)
            .unwrap_or_default()
            .into(),
    ).await?;

call js.publish with empty subject, will cause nats core route payload to respond box.
like that
img_v3_02lm_465d7128-a742-409f-9cd0-3f15f998321g

@hysyeah
Copy link
Author

hysyeah commented May 15, 2025

This should be validated on Core Nats level, with new error kind.

thank you for reply. I think this also need validated on async-nat, because empty subject name will never be valid, add a check to quickly return when the subject name is empty, avoiding unnecessary requests to the server. This also provides a clear error message.

@Jarema
Copy link
Member

Jarema commented May 16, 2025

That's exactly what I'm asking for - add that validation for client.publish. It will also cover jetstream.publish.

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.

2 participants