@@ -24,7 +24,7 @@ import (
2424 "fmt"
2525 "io"
2626 "math"
27- "math/rand"
27+ "math/rand/v2 "
2828 "net"
2929 "net/http"
3030 "net/url"
@@ -39,7 +39,6 @@ import (
3939
4040 "github.com/klauspost/compress/s2"
4141 "github.com/nats-io/jwt/v2"
42- "github.com/nats-io/nats-server/v2/internal/fastrand"
4342)
4443
4544// Type of client connection.
@@ -229,6 +228,7 @@ const (
229228
230229// Some flags passed to processMsgResults
231230const pmrNoFlag int = 0
231+
232232const (
233233 pmrCollectQueueNames int = 1 << iota
234234 pmrIgnoreEmptyQueueFilter
@@ -362,9 +362,11 @@ type outbound struct {
362362
363363const nbMaxVectorSize = 1024 // == IOV_MAX on Linux/Darwin and most other Unices (except Solaris/AIX)
364364
365- const nbPoolSizeSmall = 512 // Underlying array size of small buffer
366- const nbPoolSizeMedium = 4096 // Underlying array size of medium buffer
367- const nbPoolSizeLarge = 65536 // Underlying array size of large buffer
365+ const (
366+ nbPoolSizeSmall = 512 // Underlying array size of small buffer
367+ nbPoolSizeMedium = 4096 // Underlying array size of medium buffer
368+ nbPoolSizeLarge = 65536 // Underlying array size of large buffer
369+ )
368370
369371var nbPoolSmall = & sync.Pool {
370372 New : func () any {
@@ -703,8 +705,10 @@ type ClientOpts struct {
703705 ProxySig string `json:"proxy_sig,omitempty"`
704706}
705707
706- var defaultOpts = ClientOpts {Verbose : true , Pedantic : true , Echo : true }
707- var internalOpts = ClientOpts {Verbose : false , Pedantic : false , Echo : false }
708+ var (
709+ defaultOpts = ClientOpts {Verbose : true , Pedantic : true , Echo : true }
710+ internalOpts = ClientOpts {Verbose : false , Pedantic : false , Echo : false }
711+ )
708712
709713func (c * client ) setTraceLevel () {
710714 if c .kind == SYSTEM && ! (atomic .LoadInt32 (& c .srv .logging .traceSysAcc ) != 0 ) {
@@ -720,7 +724,7 @@ func (c *client) initClient() {
720724 c .cid = atomic .AddUint64 (& s .gcid , 1 )
721725
722726 // Outbound data structure setup
723- c .out .sg = sync .NewCond (& ( c .mu ) )
727+ c .out .sg = sync .NewCond (& c .mu )
724728 opts := s .getOpts ()
725729 // Snapshots to avoid mutex access in fast paths.
726730 c .out .wdl = opts .WriteDeadline
@@ -1691,7 +1695,7 @@ func (c *client) readLoop(pre []byte) {
16911695 return
16921696 }
16931697
1694- if cpacc && ( c .in .start .Sub (lpacc ) ) >= closedSubsCheckInterval {
1698+ if cpacc && c .in .start .Sub (lpacc ) >= closedSubsCheckInterval {
16951699 c .pruneClosedSubFromPerAccountCache ()
16961700 lpacc = time .Now ()
16971701 }
@@ -5239,7 +5243,7 @@ func (c *client) processMsgResults(acc *Account, r *SublistResult, msg, deliver,
52395243 }
52405244
52415245 var rplyHasGWPrefix bool
5242- var creply = reply
5246+ creply : = reply
52435247
52445248 // If the reply subject is a GW routed reply, we will perform some
52455249 // tracking in deliverMsg(). We also want to send to the user the
@@ -5513,7 +5517,7 @@ func (c *client) processMsgResults(acc *Account, r *SublistResult, msg, deliver,
55135517 // We already have a LEAF and this is another one.
55145518 // Flip a coin to see if we swap it or not.
55155519 // See https://github.com/nats-io/nats-server/issues/6040
5516- if fastrand .Uint32 ()% 2 == 1 {
5520+ if rand .Uint32 ()% 2 == 1 {
55175521 rsub = sub
55185522 }
55195523 }
@@ -5527,7 +5531,7 @@ func (c *client) processMsgResults(acc *Account, r *SublistResult, msg, deliver,
55275531 sindex := 0
55285532 lqs := len (qsubs )
55295533 if lqs > 1 {
5530- sindex = int (fastrand .Uint32 () % uint32 (lqs ))
5534+ sindex = int (rand .Uint32 () % uint32 (lqs ))
55315535 }
55325536
55335537 // Find a subscription that is able to deliver this message starting at a random index.
@@ -6326,12 +6330,12 @@ func (c *client) clearAccountSubs(close bool) {
63266330 // Process any qsubs here.
63276331 for _ , esub := range qsubs {
63286332 if ! spoke {
6329- srv .updateRouteSubscriptionMap (acc , esub .sub , - ( esub .n ) )
6333+ srv .updateRouteSubscriptionMap (acc , esub .sub , - esub .n )
63306334 if srv .gateway .enabled {
6331- srv .gatewayUpdateSubInterest (acc .Name , esub .sub , - ( esub .n ) )
6335+ srv .gatewayUpdateSubInterest (acc .Name , esub .sub , - esub .n )
63326336 }
63336337 }
6334- acc .updateLeafNodes (esub .sub , - ( esub .n ) )
6338+ acc .updateLeafNodes (esub .sub , - esub .n )
63356339 }
63366340 }
63376341
@@ -7030,7 +7034,7 @@ func (c *client) setFirstPingTimer() {
70307034 }
70317035 }
70327036 // We randomize the first one by an offset up to 20%, e.g. 2m ~= max 24s.
7033- addDelay := rand .Int63n (int64 (d / 5 ))
7037+ addDelay := rand .Int64N (int64 (d / 5 ))
70347038 d += time .Duration (addDelay )
70357039 // In the case of ROUTER/LEAF and when compression is configured, it is possible
70367040 // that this timer was already set, but just to detect a stale connection
0 commit comments