Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client ID appears in Get presence twice, like two clients with the same ID are present. #532

Open
Rosalita opened this issue May 27, 2022 · 0 comments
Labels
bug Something isn't working. It's clear that this does need to be fixed.

Comments

@Rosalita
Copy link
Contributor

Rosalita commented May 27, 2022

Please note this issue appears in ably-go 1.2.6 however it doesn't reproduce in 1.2.5

When a Realtime client enters their presence to a brand new channel and there is a short delay before they get channel presence, their client's ID is returned twice.

I've been able to recreate this issue with the following script.

package main

import (
	"context"
	"fmt"
	"os"
	"bytes"
	"time"
	"github.com/ably/ably-go/ably"
)


func main() {
	ctx := context.Background()

	key, _ := os.LookupEnv("ABLY_PRIVATE_KEY")

	client, err := ably.NewRealtime(
		ably.WithKey(key),
		ably.WithClientID("Client A"),
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	// To recreate the bug set channel name to a new name each time this script is run
	// this results in the Get creating a brand new channel rather than fetching an existing channel
	myChannel := client.Channels.Get("channel1")
	myChannel.Presence.Enter(ctx, nil)

	// This bug occurs when there is a delay after entering presence
	time.Sleep(time.Second * 5)

	presenceMessages, err := myChannel.Presence.Get(ctx)
	if err != nil {
		fmt.Println(err)
		return
	}

	var buffer bytes.Buffer

	for i, msg := range presenceMessages {
		if msg != nil {
			buffer.WriteString(msg.ClientID)
			// if not the last message, add a comma and a space.
			if i != len(presenceMessages)-1 {
				buffer.WriteString(", ")
			}
		}
	}
	
	fmt.Println(buffer.String())
	// When the bug happens in ably-go 1.2.6 "Client A, Client A" is printed
	// in ably-go 1.2.5 this script prints "Client A"

}

┆Issue is synchronized with this Jira Task by Unito

@Rosalita Rosalita added the bug Something isn't working. It's clear that this does need to be fixed. label May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It's clear that this does need to be fixed.
Development

No branches or pull requests

1 participant