API returning 429 in New Chat Screen
Describe the bug https://chat.stream-io-api.com/channels/messaging/query?connection_id=67d94147-0a05-1051-0200-000007349c02&api_key=qx5us2v6xvmh returned 429
SDK version
- 6.16.0
To Reproduce Steps to reproduce the behavior:
- Go to New Chat screen
- Click on some users, 8 in my case.
- Select and deselect some user(same or different) multiple times.
- See error toast "Failed to create draft channel.
(OkHttp https://chat.stream-io-api.com/...:1134) --> POST https://chat.stream-io-api.com/channels/messaging/query?connection_id=67d94147-0a05-1051-0200-000007349c02&api_key=qx5us2v6xvmh (404-byte body)
(OkHttp https://chat.stream-io-api.com/...:1134)
(OkHttp https://chat.stream-io-api.com/...:1134) {"state":false,"watch":false,"presence":false,"messages":{},"watchers":{},"members":{},"data":{"draft":true,"members":[{"user_id":"aabbcc"},{"user_id":"Qx9RyXxOWp3Rer6undefinedQ1ut7"},{"user_id":"Abdallah"},{"user_id":"vdx47uxHx4NfMQZYGy3ML"},{"user_id":"Ok4ikX8poBaYU6ZkJKKBy"},{"user_i ...
(OkHttp https://chat.stream-io-api.com/...:1134) --> END POST (404-byte body)
(OkHttp https://chat.stream-io-api.com/...:1134) curl -X POST -H "User-Agent:Chat Sample Compose / 6.16.0-DEBUG(1); StandAloneInstall; (realme; RMX3371; SDK 34; Android 14)" -H "Content-Type:application/json" -H "stream-auth-type:jwt" -H "X-Stream-Client:stream-chat-android-compose-6.16.0|os=Android 14|api_version=34|device_model=real...
Skipped: false 1 cost 21.723978 refreshRate 16647444 bit true processName io.getstream.chat.android.compose.sample.debug
(OkHttp https://chat.stream-io-api.com/...:1134) <-- 429 https://chat.stream-io-api.com/channels/messaging/query?connection_id=67d94147-0a05-1051-0200-000007349c02&api_key=qx5us2v6xvmh (140ms, 238-byte body)
(OkHttp https://chat.stream-io-api.com/...:1134) <-- END HTTP (238-byte body omitted)
(DefaultDispatcher-worker-23:1114) API call failed (attempt 1). Giving up for now, will retry when connection recovers. Error was NetworkError(message=GetOrCreateChannel failed with error: "Too many requests, check response headers for more information."
More information available at https://getstream.io/chat/docs/api_errors_response, serverErrorCode=9, statusCode=429, cause=null)
It fails for a few seconds, and then it'll work. Maybe only a test-environment issue, and I was unknowingly abusing the API?
Expected behavior It should work as expected and select all users who have been clicked, and the API should return 201.
Device:
- Vendor and model: Realme GT
- Android version: 14
Screenshots If applicable, add screenshots to help explain your problem.
Hi @Sagar0-0 ,
Thank you for the report!
The cause of this problem is because we attempt to create a draft channel each time the list of selected user changes. If this is done too often in a short amount of time, the createChannel operation could hit its rate limits on back-end - which would end up in each subsequent call returning an HTTP 429.
After the cooldown period is done, the call will went through successfully.
We will take up a task to optimise this, so that the rate limit is not hit. However, since this is an issue in the sample app and not in the SDK, we will take this up with lower priority!
Best regards, Petar
Ticket: https://linear.app/stream/issue/AND-745/compose-sample-creating-draft-channel-hits-rate-limits