Skip to content

Commit

Permalink
fix for the first crash in tinode#420
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 14, 2020
1 parent abb2a7b commit db431ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,21 @@ func (Cluster) Proxy(msg *ClusterResp, unused *bool) error {
func (c *Cluster) Route(msg *ClusterReq, rejected *bool) error {
*rejected = false
if msg.Signature != c.ring.Signature() {
log.Println("cluster Route: session signature mismatch", msg.Sess.Sid)
sid := ""
if msg.Sess != nil {
sid = msg.Sess.Sid
}
log.Println("cluster Route: session signature mismatch", sid)
*rejected = true
return nil
}
if msg.SrvMsg == nil {
sid := ""
if msg.Sess != nil {
sid = msg.Sess.Sid
}
// TODO: maybe panic here.
log.Println("cluster Route: nil server message", msg.Sess.Sid)
log.Println("cluster Route: nil server message", sid)
*rejected = true
return nil
}
Expand Down Expand Up @@ -606,7 +614,7 @@ func (c *Cluster) routeToTopic(msg *ClientComMessage, topic string, sess *Sessio
}

// Forward server response message to the node that owns topic.
func (c *Cluster) routeToTopicIntraCluster(topic string, msg *ServerComMessage) error {
func (c *Cluster) routeToTopicIntraCluster(topic string, msg *ServerComMessage, sess *Session) error {
n := c.nodeForTopic(topic)
if n == nil {
return errors.New("node for topic not found (intra)")
Expand All @@ -617,8 +625,12 @@ func (c *Cluster) routeToTopicIntraCluster(topic string, msg *ServerComMessage)
Signature: c.ring.Signature(),
Fingerprint: c.fingerprint,
RcptTo: topic,
SrvMsg: msg}
SrvMsg: msg,
}

if sess != nil {
req.Sess = &ClusterSess{Sid: sess.sid}
}
return n.route(req)
}

Expand Down
2 changes: 1 addition & 1 deletion server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (h *Hub) run() {
} else if (strings.HasPrefix(msg.rcptto, "usr") || strings.HasPrefix(msg.rcptto, "grp")) &&
globals.cluster.isRemoteTopic(msg.rcptto) {
// It is a remote topic.
if err := globals.cluster.routeToTopicIntraCluster(msg.rcptto, msg); err != nil {
if err := globals.cluster.routeToTopicIntraCluster(msg.rcptto, msg, msg.sess); err != nil {
log.Printf("hub: routing to '%s' failed", msg.rcptto)
}
} else if msg.Pres == nil && msg.Info == nil {
Expand Down

0 comments on commit db431ba

Please sign in to comment.