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

Under poor network conditions, sometimes channel.sendMessage() will return an error, when it is actually successful #2245

Open
derekchan916 opened this issue Aug 8, 2023 · 2 comments

Comments

@derekchan916
Copy link

derekchan916 commented Aug 8, 2023

I'll try to be as descriptive as possible, and please let me know if this is my issue. Attached is a video of what happens in the UI. I am using react-native. (Versions will be listed below).

Problem

https://github.com/GetStream/stream-chat-js/assets/12720511/d641acfc-bd21-4493-92b6-1fcd282deea2
Please take a look starting at the 10 second mark. There are a couple of key points here:

  • I am using the Network Link Conditioner internet restriction tool to simulate Edge networks.
  • I wait for the message to be successful until I send the next message (I'm trying to prove it's not a race condition on the frontend)
  • When the message errors, it is because the channel.sendMessage() is throwing an error timeout of 3000ms exceeded (Code will be pasted below)
  • Even though the message occurs, my other account (Pikachu) actually receives the message fine.
  • Afterwards what happens is several of issues. If the user tries to resend the message it will error out because technically there is nothing to "resend". And when I refresh the page, there will be a duplicate message that comes. (This I need to dig a little bit more into).
  • I do have enableOfflineSupport turned on

Here is the code below, it is the default code from stream chat react native

In Channel.tsx:

  const sendMessageRequest = async (
    message: MessageResponse<StreamChatGenerics>,
    retrying?: boolean,
  ) => {
    try {
      const updatedMessage = await uploadPendingAttachments(message);
      const {
       // ...default code
        user,
        ...extraFields
      } = updatedMessage;
      if (!channel.id) {
        return;
      }

      const mentionedUserIds = mentioned_users?.map(user => user.id) || [];

      const messageData = {
        attachments,
        id,
        mentioned_users: mentionedUserIds,
        parent_id,
        text: patchMessageTextCommand(text ?? '', mentionedUserIds),
        ...extraFields,
      } as StreamMessage<StreamChatGenerics>;

      let messageResponse = {} as SendMessageAPIResponse<StreamChatGenerics>;
      if (doSendMessageRequest) {
         // ...default code
      } else if (channel) {
        messageResponse = await channel.sendMessage(messageData);
      }

      if (messageResponse.message) {
        // ...default code, it doesn't reach here
      }
    } catch (err) {
      console.log(err) // THIS IS WHERE THE ERROR MESSAGE IS
      message.status = MessageStatusTypes.FAILED;
      updateMessage({...message, cid: channel.cid});

      if (enableOfflineSupport) {
       // ...default code
    }
  };

My package versions:

{
  "stream-chat": "^8.10.1",
  "react-native": "0.71.11",
}

The stream-chat-react-native code is directly forked, [v5.15.0](https://github.com/GetStream/stream-chat-react-native/releases/tag/v5.15.0)

Thanks, please let me know if you need more information.

@pomSense
Copy link

Getting the same issue on querying.

@vishalnarkhede vishalnarkhede transferred this issue from GetStream/stream-chat-js Sep 30, 2023
@khushal87
Copy link
Member

Hey @derekchan916, can you try out in the latest version of the SDK and let us know if it is still a problem for you? Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants