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

[FIXED] Inboxes suffix would contain many zeros #808

Merged
merged 2 commits into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -3,8 +3,7 @@ A [Go](http://golang.org) client for the [NATS messaging system](https://nats.io

[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fnats-io%2Fgo-nats.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fnats-io%2Fgo-nats?ref=badge_shield)
[![Go Report Card](https://goreportcard.com/badge/github.com/nats-io/nats.go)](https://goreportcard.com/report/github.com/nats-io/nats.go) [![Build Status](https://travis-ci.com/nats-io/nats.go.svg?branch=master)](http://travis-ci.com/nats-io/nats.go) [![GoDoc](https://img.shields.io/badge/GoDoc-reference-007d9c)](https://pkg.go.dev/github.com/nats-io/nats.go)
[![Coverage Status](https://coveralls.io/repos/nats-io/nats.go/badge.svg?branch=master)](https://coveralls.io/r/nats-io/nats.go?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/nats-io/nats.go)](https://goreportcard.com/report/github.com/nats-io/nats.go) [![Build Status](https://travis-ci.com/nats-io/nats.go.svg?branch=main)](https://travis-ci.com/nats-io/nats.go) [![GoDoc](https://img.shields.io/badge/GoDoc-reference-007d9c)](https://pkg.go.dev/github.com/nats-io/nats.go) [![Coverage Status](https://coveralls.io/repos/nats-io/nats.go/badge.svg?branch=main)](https://coveralls.io/r/nats-io/nats.go?branch=main)

## Installation

Expand Down
2 changes: 1 addition & 1 deletion go_test.mod
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/golang/protobuf v1.4.2
github.com/nats-io/nats-server/v2 v2.3.5-0.20210825221009-41a253dabb43
github.com/nats-io/nats-server/v2 v2.4.1-0.20210831212757-2539bbb957ef
github.com/nats-io/nkeys v0.3.0
github.com/nats-io/nuid v1.0.1
google.golang.org/protobuf v1.23.0
Expand Down
6 changes: 3 additions & 3 deletions go_test.sum
Expand Up @@ -19,9 +19,9 @@ github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU=
github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q=
github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI=
github.com/nats-io/jwt/v2 v2.0.3/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY=
github.com/nats-io/nats-server/v2 v2.3.5-0.20210825221009-41a253dabb43 h1:Sbb4QxNsccsPERg0C7uQX7/xgOCOTMIvDH9Ytb5MXsU=
github.com/nats-io/nats-server/v2 v2.3.5-0.20210825221009-41a253dabb43/go.mod h1:jgHRB+EfZisUr6j50/g7Gcah7AR8qtk3as42DJmESCk=
github.com/nats-io/nats.go v1.11.1-0.20210819195927-9053aa4200f0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nats-server/v2 v2.4.1-0.20210831212757-2539bbb957ef h1:fVi/sPmt1MjO1bA4M4jFlrCs9DYuZbpHPeKr7IQRM2Q=
github.com/nats-io/nats-server/v2 v2.4.1-0.20210831212757-2539bbb957ef/go.mod h1:TUAhMFYh1VISyY/D4WKJUMuGHg8yHtoUTuxkbiej1lc=
github.com/nats-io/nats.go v1.12.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
Expand Down
3 changes: 2 additions & 1 deletion nats.go
Expand Up @@ -3566,6 +3566,7 @@ func (nc *Conn) oldRequest(subj string, hdr, data []byte, timeout time.Duration)
const (
InboxPrefix = "_INBOX."
inboxPrefixLen = len(InboxPrefix)
replySuffixLen = 8 // Gives us 62^8
rdigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
base = 62
)
Expand Down Expand Up @@ -3615,7 +3616,7 @@ func (nc *Conn) newRespInbox() string {
sb.WriteString(nc.respSubPrefix)

rn := nc.respRand.Int63()
for i := 0; i < nuidSize; i++ {
for i := 0; i < replySuffixLen; i++ {
sb.WriteByte(rdigits[rn%base])
rn /= base
}
Expand Down
34 changes: 34 additions & 0 deletions nats_test.go
Expand Up @@ -2702,3 +2702,37 @@ func TestCustomInboxPrefix(t *testing.T) {
t.Fatalf("did not receive ok: %q", resp.Data)
}
}

func TestRespInbox(t *testing.T) {
s := RunServerOnPort(-1)
defer s.Shutdown()

nc, err := Connect(s.ClientURL())
if err != nil {
t.Fatalf("Expected to connect to server, got %v", err)
}
defer nc.Close()

if _, err := nc.Subscribe("foo", func(msg *Msg) {
lastDot := strings.LastIndex(msg.Reply, ".")
if lastDot == -1 {
msg.Respond([]byte(fmt.Sprintf("Invalid reply subject: %q", msg.Reply)))
return
}
lastToken := msg.Reply[lastDot+1:]
if len(lastToken) != replySuffixLen {
msg.Respond([]byte(fmt.Sprintf("Invalid last token: %q", lastToken)))
return
}
msg.Respond(nil)
}); err != nil {
t.Fatalf("subscribe failed: %s", err)
}
resp, err := nc.Request("foo", []byte("check inbox"), time.Second)
if err != nil {
t.Fatalf("Request failed: %v", err)
}
if len(resp.Data) > 0 {
t.Fatalf("Error: %s", resp.Data)
}
}