@@ -19,6 +19,7 @@ package internal
1919import (
2020 "encoding/binary"
2121 "encoding/json"
22+ "fmt"
2223 "net"
2324 "runtime/debug"
2425 "strconv"
@@ -37,7 +38,6 @@ import (
3738
3839type _Conn struct {
3940 sync.Mutex
40- tracked uint32 // Whether the connection was already tracked or not.
4141 proto lp.Proto
4242 adp lp.ProtoAdapter
4343 socket net.Conn
@@ -187,17 +187,17 @@ func (c *_Conn) subscribe(msg lp.Subscribe, topic *security.Topic, sub *lp.Subsc
187187 return err
188188 }
189189 }
190- if exists := c .subs .Exist (key ); exists && ! msg .IsForwarded && Globals .Cluster .isRemoteContract (string (c .clientID .Contract ())) {
190+ if exists := c .subs .Exist (key ); exists && ! msg .IsForwarded && Globals .Cluster .isRemoteContract (fmt . Sprint (c .clientID .Contract ())) {
191191 // The contract is handled by a remote node. Forward message to it.
192192 if err := Globals .Cluster .routeToContract (& msg , topic , message .SUBSCRIBE , & message.Message {}, c ); err != nil {
193193 log .ErrLogger .Err (err ).Str ("context" , "conn.subscribe" ).Int64 ("connid" , int64 (c .connID )).Msg ("unable to subscribe to remote topic" )
194194 return err
195195 }
196- // Add the subscription to Counters
197196 } else {
198197 messageId , err := store .Subscription .NewID ()
199198 if err != nil {
200199 log .ErrLogger .Err (err ).Str ("context" , "conn.subscribe" )
200+ return err
201201 }
202202 if first := c .subs .Increment (topic .Topic [:topic .Size ], key , messageId ); first {
203203 // Subscribe the subscriber
@@ -232,7 +232,7 @@ func (c *_Conn) unsubscribe(msg lp.Unsubscribe, topic *security.Topic) (err erro
232232 // Decrement the subscription counter
233233 c .service .meter .Subscriptions .Dec (1 )
234234 }
235- if ! msg .IsForwarded && Globals .Cluster .isRemoteContract (string (c .clientID .Contract ())) {
235+ if ! msg .IsForwarded && Globals .Cluster .isRemoteContract (fmt . Sprint (c .clientID .Contract ())) {
236236 // The topic is handled by a remote node. Forward message to it.
237237 if err := Globals .Cluster .routeToContract (& msg , topic , message .UNSUBSCRIBE , & message.Message {}, c ); err != nil {
238238 log .ErrLogger .Err (err ).Str ("context" , "conn.unsubscribe" ).Int64 ("connid" , int64 (c .connID )).Msg ("unable to unsubscribe to remote topic" )
@@ -252,6 +252,7 @@ func (c *_Conn) publish(pkt lp.Publish, topic *security.Topic, m *lp.PublishMess
252252 subscriptions , err := store .Subscription .Get (c .clientID .Contract (), topic .Topic )
253253 if err != nil {
254254 log .ErrLogger .Err (err ).Str ("context" , "conn.publish" )
255+ return err
255256 }
256257 pubMsg := & message.Message {
257258 MessageID : pkt .MessageID ,
@@ -300,12 +301,13 @@ func (c *_Conn) publish(pkt lp.Publish, topic *security.Topic, m *lp.PublishMess
300301 c .service .meter .OutMsgs .Inc (int64 (msgCount ))
301302 c .service .meter .OutBytes .Inc (pubMsg .Size () * int64 (msgCount ))
302303
303- if ! pkt .IsForwarded && Globals .Cluster .isRemoteContract (string (c .clientID .Contract ())) {
304+ if ! pkt .IsForwarded && Globals .Cluster .isRemoteContract (fmt . Sprint (c .clientID .Contract ())) {
304305 if err = Globals .Cluster .routeToContract (& pkt , topic , message .PUBLISH , pubMsg , c ); err != nil {
305306 log .ErrLogger .Err (err ).Str ("context" , "conn.publish" ).Int64 ("connid" , int64 (c .connID )).Msg ("unable to publish to remote topic" )
307+ return err
306308 }
307309 }
308- return err
310+ return nil
309311}
310312
311313// Load all stored messages and resend them to ensure DeliveryMode > 1,2 even after an application crash.
0 commit comments