Repository navigation
TypeError: Network request failed randomly in IOS #49037
Description
Activity
- addedNeeds: ReproThis issue could be improved with a clear list of steps to reproduce the issue.This issue could be improved with a clear list of steps to reproduce the issue.
on Jan 29, 2025 - changed the title
[-]TypeError: Network request failed randomly[/-][+]TypeError: Network request failed randomly in IOS[/+]on Jan 29, 2025 Warning
Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:
- If your bug is UI related: a Snack
- If your bug is build/upgrade related: a project using our Reproducer Template
- Otherwise send us a Pull Request with the RNTesterPlayground.js edited to reproduce your bug.
please any updates , this is a critical issue.
- addedNeeds: AttentionIssues where the author has responded to feedback.Issues where the author has responded to feedback.and removed
on Jan 29, 2025 Hey @Nader-CS,
Could you please share a reproducible example for this issue? You can use this template: Reproducer Template.
Additionally, based on the output of npx react-native info, it looks like you are currently using the old architecture. Would you mind checking if the issue persists when using the new architecture as well?
Reacted by Nicola Corti- added and removedNeeds: AttentionIssues where the author has responded to feedback.Issues where the author has responded to feedback.
on Jan 29, 2025 unfortunately , this is commerical app and also can't re-produce it :( @sarthak-d11
- addedNeeds: AttentionIssues where the author has responded to feedback.Issues where the author has responded to feedback.and removed
on Feb 2, 2025 7 remaining items
Thanks!
Do you mind sharing your code snippet for it?
For extra context, I also have a web app built in React using the same RTK query used in my React Native app and it happens on iOS or Android phones using the web app.
Reacted by abitlingAlright - I believe I have found a consistent way of reproducing this error on my end. I slowed my network connection, put app in background for 30 seconds while my RTK query is polling at an interval of 5 seconds.
- Launch your iOS app in a simulator
- Depending on the Xcode version you're using, download from Apple's website the
Additional_Tools_for_Xcode_[version]. In my case, it wasAdditional_Tools_for_Xcode_16.2. - Double click on the
.dmgfile and go to theHardwarefolder and double click on theNetwork Link Conditioner.prefPanefile to install theNetwork Link Conditionerapplication. - One you have the
Network Link Conditioneropened, select theVery Bad Networkprofile - Set any RTK Query request using the
useQueryhook and setpollingIntervalto 5 seconds. - If you're using Reactotron, filter out the logs to only see API requests.
- Wait to see one request come through. Count to 4 - 5 seconds and right before the next request comes in, put the app in background and count to 30 - 35 seconds.
- Open the app and you will that RTK query will fail almost every time if you time it well.
I only used the network link conditioner to be able to repeat it almost every time but it's not needed.
Since under the hood I'm using axios to fetch the requests, here's what gets returned every single time with a status code of
0.{ "message": "timeout of 30000ms exceeded", "name": "AxiosError", "description": "undefined", "number": "undefined", "fileName": "undefined", "lineNumber": "undefined", "columnNumber": "undefined", "code": "ECONNABORTED", "status": "undefined", "config": { "timeout": "30000" } }My current solution now is to listen to this specific error code and instead of showing an error, I show a loader since I'm polling and API will be trying the request again.
Hope this was helpful!!
Thanks!
Do you mind sharing your code snippet for it?
For extra context, I also have a web app built in React using the same RTK query used in my React Native app and it happens on iOS or Android phones using the web app.
I cannot share the code snippet here, but all I can say is, I have just delayed the function call by 500ms using
setTimeout, This function is responsible to initiate the RTK Query to fetch data. I my case I am not performing polling requests, I understand, it seem to be difficult to delay a polling request.I strongly believe, this should be caused by the underlying Fetch API. Can somebody try to reproduce this with a bare RN project and Fetch API so that we can eliminate the possibility of RTK Query causing the issue.
Thanks!
Do you mind sharing your code snippet for it?
For extra context, I also have a web app built in React using the same RTK query used in my React Native app and it happens on iOS or Android phones using the web app.I cannot share the code snippet here, but all I can say is, I have just delayed the function call by 500ms using
setTimeout, This function is responsible to initiate the RTK Query to fetch data. I my case I am not performing polling requests, I understand, it seem to be difficult to delay a polling request.I strongly believe, this should be caused by the underlying Fetch API. Can somebody try to reproduce this with a bare RN project and Fetch API so that we can eliminate the possibility of RTK Query causing the issue.
I see. You’re probably using lazy query in that case and you’re delaying your function call by 500ms.
Based on what I experienced, I think in your case, if you were to perfectly time the request before you put the app in background mode, the issue could still happen.
I strongly believe that the issue has to do with the app going to background while the request is in flight and after 30 seconds or so, usually the OS itself will kill any TCP connection that was established when the app was open. So I think if the fetch library or axios throws an error
ECONNABORTED, I think it’s ok and it’s expected.So I’m thinking, maybe there’s nothing to fix here if it’s happening only by temporarily putting the phone in background.
If it’s happening while the app is open all the time, then that’s not the issue I’m experiencing.
Take a look at the other link shared by OP: reduxjs/redux-toolkit#4825 (comment)
It seems that is issue is only happening by putting the app in background mode.
Thanks!
Do you mind sharing your code snippet for it?
For extra context, I also have a web app built in React using the same RTK query used in my React Native app and it happens on iOS or Android phones using the web app.I cannot share the code snippet here, but all I can say is, I have just delayed the function call by 500ms using
setTimeout, This function is responsible to initiate the RTK Query to fetch data. I my case I am not performing polling requests, I understand, it seem to be difficult to delay a polling request.
I strongly believe, this should be caused by the underlying Fetch API. Can somebody try to reproduce this with a bare RN project and Fetch API so that we can eliminate the possibility of RTK Query causing the issue.I see. You’re probably using lazy query in that case and you’re delaying your function call by 500ms.
Based on what I experienced, I think in your case, if you were to perfectly time the request before you put the app in background mode, the issue could still happen.
I strongly believe that the issue has to do with the app going to background while the request is in flight and after 30 seconds or so, usually the OS itself will kill any TCP connection that was established when the app was open. So I think if the fetch library or axios throws an error
ECONNABORTED, I think it’s ok and it’s expected.So I’m thinking, maybe there’s nothing to fix here if it’s happening only by temporarily putting the phone in background.
If it’s happening while the app is open all the time, then that’s not the issue I’m experiencing.
Take a look at the other link shared by OP: reduxjs/redux-toolkit#4825 (comment)
It seems that is issue is only happening by putting the app in background mode.
Its not about perfectly timing the app state change.
In my case its not a polling request, its a mandatory network request which fetches the necessary information from the server (something like refreshing the subscription information for the user from server as soon as app comes back to Foreground). I need to make this network request every time app comes back to foreground.
I do not see any strong reason why OS itself would kill the TCP connection. Especially when the app is put back to foreground from background. I would term this as a bug instead of expected behaviour.
Let me know if I am missing on any necessary information.
Thanks!
Do you mind sharing your code snippet for it?
For extra context, I also have a web app built in React using the same RTK query used in my React Native app and it happens on iOS or Android phones using the web app.I cannot share the code snippet here, but all I can say is, I have just delayed the function call by 500ms using
setTimeout, This function is responsible to initiate the RTK Query to fetch data. I my case I am not performing polling requests, I understand, it seem to be difficult to delay a polling request.
I strongly believe, this should be caused by the underlying Fetch API. Can somebody try to reproduce this with a bare RN project and Fetch API so that we can eliminate the possibility of RTK Query causing the issue.I see. You’re probably using lazy query in that case and you’re delaying your function call by 500ms.
Based on what I experienced, I think in your case, if you were to perfectly time the request before you put the app in background mode, the issue could still happen.
I strongly believe that the issue has to do with the app going to background while the request is in flight and after 30 seconds or so, usually the OS itself will kill any TCP connection that was established when the app was open. So I think if the fetch library or axios throws an errorECONNABORTED, I think it’s ok and it’s expected.
So I’m thinking, maybe there’s nothing to fix here if it’s happening only by temporarily putting the phone in background.
If it’s happening while the app is open all the time, then that’s not the issue I’m experiencing.
Take a look at the other link shared by OP: reduxjs/redux-toolkit#4825 (comment)
It seems that is issue is only happening by putting the app in background mode.Its not about perfectly timing the app state change.
In my case its not a polling request, its a mandatory network request which fetches the necessary information from the server (something like refreshing the subscription information for the user from server as soon as app comes back to Foreground). I need to make this network request every time app comes back to foreground.
I do not see any strong reason why OS itself would kill the TCP connection. Especially when the app is put back to foreground from background. I would term this as a bug instead of expected behaviour.
Let me know if I am missing on any necessary information.
I see what you’re saying. Our use case is probably different. In my case, I understand why the error happens and I think it makes sense. For your use case, if you’re fetching when app comes to foreground and it is throwing an error prematurely unless you put that delay, that’s probably a bug.
Reacted by abitlingany update about this ?
I realized something new — most of the API failures are related to the polling interval prop.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
- addedStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.and removedStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
on Apr 12, 2026 This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
- addedStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
on Oct 10, 2026 still exist
Reacted by abitling- removedStaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
on Oct 11, 2026
Description
some users reported network request failed using rtk query or
TypeError: Network request failed randomlyfor some api's and others works fine , according to this issue opened by me in redux toolkit link , the issue arises from react native environment , this issue happen randomly in ios , i mean same user in other device can request this api and works fine , the request not even reaches to our server.api.configprofile.js
Errorview.jsx
Steps to reproduce
useQuery)React Native Version
0.75.4
Affected Platforms
Runtime - iOS
Output of
npx react-native infoStacktrace or Logs
Reproducer
commercial app
Screenshots and Videos