Skip to content

server/topic.Subscribe can produce duplicate subscriber IDs #712

Closed
@peterbourgon

Description

@peterbourgon

subscriberID := rand.Int()

// Subscribe subscribes to this topic
func (t *topic) Subscribe(s subscriber, userID string, cancel func()) int {
	t.mu.Lock()
	defer t.mu.Unlock()
	subscriberID := rand.Int() // <---- here
	t.subscribers[subscriberID] = &topicSubscriber{
		userID:     userID, // May be empty
		subscriber: s,
		cancel:     cancel,
	}
	t.lastAccess = time.Now()
	return subscriberID
}

Nothing prevents subscriberID := rand.Int() from producing an integer which is already present in the t.subscribers map. In that case, the previous subscriber is over-written.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🪲 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions