stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

Messages in channel fail to load/appear

Open AndrewSB opened this issue 1 year ago • 1 comments

What did you do?

tried to scroll to the top of a channel, to see my older messages

What did you expect to happen?

being able to scroll all the way to the beginning of a thread

What happened instead?

instead, parts of my history were unavailable, i couldn't scroll back past a point

I see the following logs as i scroll to the top of the channel :

2022-08-10 09:27:19.362 [ERROR] [com.apple.NSURLSession-delegate] [RequestDecoder.swift:51] [decodeRequestResponse(data:response:error:)] > API request failed with status code: 400, response:
{
  "code" : 4,
  "message" : "GetOrCreateChannel failed with error: \"Message with id 96c68774-1ad1-418b-a45a-c8974d21aafc doesn't exist\"",
  "more_info" : "https:\/\/getstream.io\/chat\/docs\/api_errors_response",
  "StatusCode" : 400,
  "duration" : "0.00ms"
})

the oldest message being displayed in the channel is a message that failed to send, my guess is the SDK encounters this message that's failed to send, requests it from the server, receives an error and then stops fetching older messages for some reason.

not sure if this should be here or in the low level SDK

AndrewSB avatar Aug 10 '22 16:08 AndrewSB

Hey @AndrewSB,

Thanks for reporting this. Moving it to our low-level client repo, since the issue is there. We will analyze it and get back to you when we have an update.

In the meantime, deleting the message or sending new ones to the channel should solve it for that particular channel.

Best, Martin

martinmitrevski avatar Aug 11 '22 11:08 martinmitrevski

Hi @AndrewSB , we believe to have found the issue, which is fixed here: https://github.com/GetStream/stream-chat-swift/pull/2258 Could you give it a try and let us know if it works?

polqf avatar Aug 30 '22 14:08 polqf

Hi!

This issue is now solved in the 4.21.1 release.

Thank you for your patience!

Best, Nuno

nuno-vieira avatar Sep 06 '22 15:09 nuno-vieira

Hey! we just tested with the new version and it looks like the problem is actually worse, now we see this more often even when .isLocalStorage = false

I can get some logs for you sometime tomorrow, maybe the underlying issue wasn't https://github.com/GetStream/stream-chat-swift/pull/2258

AndrewSB avatar Sep 07 '22 23:09 AndrewSB

Hi @AndrewSB,

Just clarify, for this to happen, the 25 message needs to fail right?

Yes, logs would be nice very helpful.

We will re-open the issue then and resume the investigation, sorry for the inconvenience.

Best, Nuno

nuno-vieira avatar Sep 08 '22 09:09 nuno-vieira

so it looks like the logs i see both when i open the channel, and when i scroll to the top are

2022-09-08 13:37:57.892 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.

repeated many times

let me see if i can get more details.

AndrewSB avatar Sep 08 '22 20:09 AndrewSB

i think i understand the bug, it seems like incorrect state in the ChannelController somehow.

on ChannelController.swift:741, both messageId and lastFetchedMessageId are nil, so it's never able to load any previous messages

this is on release 4.21.1. let me try the latest to see if it's any different

AndrewSB avatar Sep 08 '22 20:09 AndrewSB

there must be an edge case that was missed in https://github.com/GetStream/stream-chat-swift/pull/2258

let me know how i can help to solve this

AndrewSB avatar Sep 08 '22 21:09 AndrewSB

Hi @AndrewSB. Could you please let us know what's the flow that leads to calling loadPreviousMessages for you? You should have called synchronize before, that should have set a value for lastFetchedMessageId. We're investigating it.

polqf avatar Sep 09 '22 07:09 polqf

We have created a branch for you to test: https://github.com/GetStream/stream-chat-swift/pull/2279

But we believe there can be something you are doing within your flow that's not following the expected order (synchronize -> loadPreviousMessages). It is looks like you were only fetching from DB. Please give us some more context so we are sure we are solving the issue for you

polqf avatar Sep 09 '22 08:09 polqf

@martinmitrevski i think this might be related to that workaround we did to prevent being booted out of a chat thread

this is how we create a channel destination, i don't believe its synchronized in the solution we came up with together

AndrewSB avatar Sep 10 '22 02:09 AndrewSB

going to try doing a chatController.synchronize() right before we return the ChatThreadView

AndrewSB avatar Sep 10 '22 02:09 AndrewSB

ok, still doesn't work, but now what i see is a bunch of

2022-09-09 19:19:58.709 [ERROR] [com.apple.NSURLSession-delegate] [RequestDecoder.swift:67] [decodeRequestResponse(data:response:error:)] > API request failed with status code: 429, code: 9 response:
{
  "code" : 9,
  "message" : "GetOrCreateChannel failed with error: \"Too many requests for user: 5cb05d045b81370e679a1fcb, check response headers for more information.\"",
  "more_info" : "https:\/\/getstream.io\/chat\/docs\/api_errors_response",
  "details" : [

  ],
  "StatusCode" : 429,
  "duration" : ""
})

and i no longer get the

2022-09-08 13:37:57.892 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.

logs

going to try your bugfix/pagination-edge-case branch now

AndrewSB avatar Sep 10 '22 02:09 AndrewSB

hey @AndrewSB,

I don't think that's the problem, since syncronize is also called in the view model, so I guess the error you get is because you call it too many times.

Please let us know how the branch works for you. If it doesn't help, we can have a call early next week to go through your issue.

Best, Martin

martinmitrevski avatar Sep 10 '22 06:09 martinmitrevski

yeah, i think this branch is working. @martinmitrevski can we whatever fix that is patched into the main version?

AndrewSB avatar Sep 12 '22 18:09 AndrewSB

hey @AndrewSB, this is merged in the develop branch in our StreamChat repo. This week there's no release planned, so you can use it in the SwiftUI SDK by creating a branch pointing to StreamChat's develop branch.

martinmitrevski avatar Sep 14 '22 06:09 martinmitrevski

hey! we had this working on https://github.com/GetStream/stream-chat-swift/commit/9a39117a4677254a85464dbdcd4a4f4354e9792d, but after updating to https://github.com/GetStream/stream-chat-swift/commit/88f325da010642aa0e15452a1518164458d25190 it looks like the problem has re-appeared

AndrewSB avatar Sep 16 '22 03:09 AndrewSB

HI @AndrewSB!

You are seeing again the "You can't load new messages when there are no messages in the channel." error log?

It is weird, that commit does not change anything related to this, theoretically at least.

Best, Nuno

nuno-vieira avatar Sep 16 '22 16:09 nuno-vieira

yup! sorry for the delay, got caught up with some other work

i just tested on https://github.com/GetStream/stream-chat-swift/commit/e729ddecab8424d0eb1b6e7f874dcd88a27c1b23, and i'm seeing those logs

2022-09-22 16:13:42.256 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.280 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.280 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.280 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.299 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.299 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.
2022-09-22 16:13:42.314 [ERROR] [main] [ChannelController.swift:741] [loadPreviousMessages(before:limit:completion:)] > You can't load new messages when there is no messages in the channel.

AndrewSB avatar Sep 22 '22 23:09 AndrewSB

testing with the latest now, just to make sure you haven't fixed it in the last 3 days (checking out https://github.com/GetStream/stream-chat-swift/commit/e6c14c8b05abf4024898cd78ee72303fa6def61f)

AndrewSB avatar Sep 22 '22 23:09 AndrewSB

it seems to work on the latest commit. was there a change that was made that you expected to fix it with? i'm wary of removing my version pin unless you believe you've made a change that actually solves this

AndrewSB avatar Sep 22 '22 23:09 AndrewSB

The changes you are interested in should be the ones added in https://github.com/GetStream/stream-chat-swift/commit/233455651bb239c255f56f6f74d83fd4ba9a1a65 (PR: https://github.com/GetStream/stream-chat-swift/pull/2298)

polqf avatar Sep 26 '22 10:09 polqf

ahh awesome, cool. i think this is safe to close for now. we'll pin to that commit and take the next release that comes out. thanks @polqf!

AndrewSB avatar Sep 26 '22 18:09 AndrewSB

Happy to hear that @AndrewSB 😄

polqf avatar Sep 27 '22 06:09 polqf