Skip to content

Commit

Permalink
yet another fix for tinode#738
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 13, 2022
1 parent 0631fba commit f509a96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
8 changes: 6 additions & 2 deletions server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ func (h *Hub) topicUnreg(sess *Session, topic string, msg *ClientComMessage, rea
// Case 1.1: topic is online
if (!asUid.IsZero() && t.owner == asUid) || (t.cat == types.TopicCatP2P && t.subsCount() < 2) {
// Case 1.1.1: requester is the owner or last sub in a p2p topic

t.markPaused(true)
hard := true
if msg != nil && msg.Del != nil {
hard = msg.Del.Hard
// Soft-deleting does not make sense for p2p topics.
hard = msg.Del.Hard || t.cat == types.TopicCatP2P
}
if err := store.Topics.Delete(topic, hard); err != nil {
t.markPaused(false)
Expand Down Expand Up @@ -446,6 +446,10 @@ func (h *Hub) topicUnreg(sess *Session, topic string, msg *ClientComMessage, rea
}

if len(subs) == 0 {
if tcat == types.TopicCatP2P {
// No subscribers: delete.
store.Topics.Delete(topic, true)
}
sess.queueOut(InfoNoActionReply(msg, now))
return nil
}
Expand Down
23 changes: 6 additions & 17 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2945,27 +2945,16 @@ func (t *Topic) replyDelMsg(sess *Session, asUid types.Uid, asChan bool, msg *Cl
return nil
}

// Shut down the topic in response to {del what="topic"} request
// See detailed description at hub.topicUnreg()
// 1. Checks if the requester is the owner. If so:
// 1.2 Evict all sessions
// 1.3 Ask hub to unregister self
// 1.4 Exit the run() loop
// 2. If requester is not the owner:
// 2.1 If this is a p2p topic:
// 2.1.1 Check if the other subscription still exists, if so, treat request as {leave unreg=true}
// 2.1.2 If the other subscription does not exist, delete topic
// 2.2 If this is not a p2p topic, treat it as {leave unreg=true}
// Handle request to delete the topic {del what="topic"}.
// 1. If requester is the owner then it should have been handled at the hub, log an error.
// 2. If requester is not the owner, treat it like {leave unsub=true}.
func (t *Topic) replyDelTopic(sess *Session, asUid types.Uid, msg *ClientComMessage) error {
if t.owner != asUid {
// Cases 2.1.1 and 2.2
if t.cat != types.TopicCatP2P || t.subsCount() == 2 {
return t.replyLeaveUnsub(sess, msg, asUid)
}
return t.replyLeaveUnsub(sess, msg, asUid)
}

// Notifications are sent from the topic loop.

// This is an indication of a bug.
logs.Err.Println("replyDelTopic called by owner (SHOULD NOT HAPPEN!)")
return nil
}

Expand Down

0 comments on commit f509a96

Please sign in to comment.