Skip to content

[Bug]: Group membership error/loop scenario #137

@Zyell

Description

@Zyell

What happened?

I encountered a scenario with group membership removal and then subsequent syncing over a stream that results in either an error or an infinite streaming of messages. I created a code example using the beelay_core test suite. I do not get consistent behavior between runs of this code, it exhibits one of the 2 aforementioned states. The scenario is as follows:

  1. Create alice and bob
  2. alice creates a group and adds bob to the group
  3. alice and bob synchronize
  4. alice removes bob from the group
  5. alice and bob synchronize and get stuck in an infinite message exchange or exhibit the error in the attached log snippet.
#[test]
fn test_group_membership_changes() {
    init_logging();
    let mut network = Network::new();
    let alice = network.create_peer("alice").build();
    let bob = network.create_peer("bob").build();

    let bob_contact = network.beelay(&bob).contact_card().unwrap();
    let group = network.beelay(&alice).create_group(vec![]).unwrap();
    network
        .beelay(&alice)
        .add_member_to_group(AddMemberToGroup {
            group_id: group,
            member: KeyhiveEntityId::Individual(bob_contact.clone()),
            access: MemberAccess::Admin,
        })
        .unwrap();

    // Now connect to bob and sync
    // Now, sync with bob
    let ConnectedPair {
        left_to_right: alice_to_bob,
        ..
    } = network.connect_stream(&alice, &bob);

    // Sync should have happened now as we run until quiescent

    // Now disconnect from bob
    network.beelay(&alice).disconnect(alice_to_bob);

    // remove bob from the group
    network
        .beelay(&alice)
        .remove_member_from_group(RemoveMemberFromGroup {
            group_id: group,
            member: KeyhiveEntityId::Individual(bob_contact),
        })
        .unwrap();


    // Now connect to bob and sync
    // Now, sync with bob
    let ConnectedPair {
        left_to_right: alice_to_bob,
        ..
    } = network.connect_stream(&alice, &bob);
    // NOTE: we get stuck in the connected stream infinitely...

    // Sync should have happened now as we run until quiescent

    // Now disconnect from bob
    network.beelay(&alice).disconnect(alice_to_bob);

}

Version

Latest code in main branch

Which librraies in this workspace are impacted?

beelay-core

On which environment did you encounter this on?

System code

Which OSes have you noticed the issue on?

Fedora

Relevant log output

2025-06-02T23:51:15.314850Z ERROR beelay_core::network::streams:328: error handling stream message, disconnnecting, err: Receive("received unexpected hello message")
    at beelay/beelay-core/src/network/streams.rs:328 on test_group_membership_changes ThreadId(2)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions