Skip to content
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

Durable field not being validated before being set from queue name #840

Closed
saschahagedorn-f3 opened this issue Oct 7, 2021 · 0 comments · Fixed by #841
Closed

Durable field not being validated before being set from queue name #840

saschahagedorn-f3 opened this issue Oct 7, 2021 · 0 comments · Fixed by #841
Assignees
Labels
bug Confirmed reproducible bug

Comments

@saschahagedorn-f3
Copy link

saschahagedorn-f3 commented Oct 7, 2021

Defect

The docs state that queue names can be divided by dots for hierarchical purposes:

Queue group names follow the same naming rules as subjects. Foremost, they are case sensitive and cannot contain whitespace. Consider structuring queue groups hierarchically using .

When using a queue name with dots and creating a queue subscription with QueueSubscribe the method returns an error: "context deadline exceeded". In js.go the Durable field is directly set from the queue argument without validation. When using the nats.Durable option the name is validated and does not allow for dots and returns an error: "nats: invalid durable name".

Versions of nats.go and the nats-server if one was involved:

  • nats-server: 2.6.1
  • nats.go: v1.12.3

OS/Container environment:

  • Ubuntu 20.04.3
  • Docker

Steps or code to reproduce the issue:

package main

import (
	"fmt"

	"github.com/nats-io/nats.go"
)

func main() {
	nc, err := nats.Connect("localhost:4222")
	if err != nil {
		panic(err)
	}

	js, err := nc.JetStream()
	if err != nil {
		panic(err)
	}

	_, err = js.AddStream(&nats.StreamConfig{
		Name:     "EventStream",
		Subjects: []string{"EventStream.*"},
	})
	if err != nil {
		panic(err)
	}

	_, err = js.QueueSubscribe("EventStream.someSubject", "some.queue", func(msg *nats.Msg) {}) // context deadline exceeded
        //_, err = js.QueueSubscribe("EventStream.someSubject", "some-queue", func(msg *nats.Msg) {}) // ok
	//_, err = js.QueueSubscribe("EventStream.someSubject", "some.queue", func(msg *nats.Msg) {}, nats.Durable("some.queue")) // nats: invalid durable name
	//_, err = js.QueueSubscribe("EventStream.someSubject", "some.queue", func(msg *nats.Msg) {}, nats.Durable("some-queue")) // ok
	if err != nil {
		panic(err)
	}

	fmt.Println("subscription successfully created")
}

Expected result:

QueueSubscribe returns "nats: invalid durable name".

Actual result:

QueueSubscribe returns "context deadline exceeded".

@saschahagedorn-f3 saschahagedorn-f3 added the bug Confirmed reproducible bug label Oct 7, 2021
kozlovic added a commit that referenced this issue Oct 7, 2021
When calling `js.QueueSubscribe[Sync](subject, queue_name)`, if
no durable name is provided, the queue name is used as the durable
name, so the same restriction applies

Resolves #840

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed reproducible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants