Subscription does not return and blocks further RPC calls

Hey guys, I’ve hit another weird problem.

I have 4 subscriptions:

  • MyStudentInfo
  • MyPet
  • MyAvailableTokens
  • MyFriends

After these 4 subscriptions are subscribed, I also call a bunch of other methods and subscriptions.

On the DDP, I can see that the documents for the first 3 are returned, and the subs are marked as ready. The thing is the 4th one does not return anything at all, and no further messages are received, even though the client/server does a ping/pong just fine.

Here’s a screen capture of the messages:

This is what it should look like when it works:

The 4th subscription (MyFriends) is really simple:

    Meteor.publish('MyFriends', function () {
        let currentUserId = UserControl.getUserId();
        if (currentUserId)
            return FriendsCollection.find({ $or: [{ Student1Id: currentUserId }, { Student2Id: currentUserId }] });
    });

I checked MongoDB to call the same search directly on the DB and it returns just fine.

Thereafter, this user’s account becomes unresponsive, and is unable to log out. It does not affect other users.

When I reload the page, the same thing happens again. The DDP works fine at first and then we call these 4 subscriptions and the same thing repeats.

If I restart the server, the problem goes away.

What could cause the account to reach this state?

Any ideas or suggestions greatly appreciated!

I removed the pub/sub for “MyFriends”, and the problem now activates at another pub/sub down the chain called “MyChatBuddies”, that also involves the FriendsCollection:

Meteor.publishComposite('MyChatBuddies', function () {

        let currentUserId = UserControl.getUserId();
        if (!currentUserId) return;

        if (UserControl.IsStudent()) {
            return {
                find: function () {
                    return StudentsCollection.find(
                        { StudentId: currentUserId },
                        { fields: { Name: 1, AvatarPictureURL: 1, StudentId: 1 }}
                    );
                },
                children: [
                    {
                        find: function (student) {
                            return FriendsCollection.find(
                                { $or: [{ Student1Id: student.StudentId },
                                        { Student2Id: student.StudentId } ]
                                }
                            );
                        },
                        children: [
                            {
                                find: function (friend) {
                                    return StudentsCollection.find(
                                        { StudentId: friend.Student1Id === currentUserId ? friend.Student2Id : friend.Student1Id },
                                        { fields: { Name: 1, AvatarPictureURL: 1, StudentId: 1 } }
                                    );
                                }
                            }
                        ]
                    },
                    {
                        find: function (student) {
                            return MentorshipsCollection.find(
                                { StudentId: currentUserId, Status: MentorshipStatus.Connected },
                            );
                        },
                        children: [
                            {
                                find: function (mentorship) {
                                    return TeachersCollection.find(
                                        { TeacherId: mentorship.TeacherId },
                                        { fields: { Name: 1, AvatarPictureURL: 1, TeacherId: 1 } }
                                    );
                                }
                            }
                        ]
                    }
                ],
            }
        }

        else if (UserControl.IsTeacher()) {
            return {
                find: function () {
                    return TeachersCollection.find(
                        { TeacherId: currentUserId },
                        { fields: { Name: 1, AvatarPictureURL: 1, TeacherId: 1 } }
                    );
                },
                children: [
                    {
                        find: function (teacher) {
                            return MentorshipsCollection.find(
                                { TeacherId: teacher.TeacherId, Status: MentorshipStatus.Connected },
                            );
                        },
                        children: [
                            {
                                find: function (mentorship) {
                                    return StudentsCollection.find(
                                        { StudentId: mentorship.StudentId },
                                        { fields: { Name: 1, AvatarPictureURL: 1, StudentId: 1 } }
                                    );
                                }
                            }
                        ]
                    },
                ]
            }
        }

    });

When I reload the page, the DPP connection works fine, but gets stuck

Is there something I’m doing wrongly with my FriendsCollection? Is there a way to clean/reset it? I have created Indices for both Student1Id and Student2Id.

As before, I can query for the affected users’ friends in MongoDB Atlas, and restarting the server fixes the problem. That’s why I don’t feel that it’s a database issue.

Any pointers would be greatly appreciated!