ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.48k stars 13.53k forks source link

bug: Android HTTP post requests #29452

Closed marshall86 closed 2 weeks ago

marshall86 commented 2 weeks ago

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

I'm using Angular with Ionic and Capacitor in my project since 6 years now and I recently noticed that on Android, when you perform an HTTP POST request and immediately put the App in background, the API request goes in a sort of loop and it get triggered multiple times. For example, let's say you call an API "getSomething" and immediately put the App in background or you open and close the App ( we know that Android, after a few seconds , get in an idle state) that Api is called multiple times (you can see it if you debug on the phone) or maybe it's called only once but the server still get the same request N-times.

It's fair to say that the API i'm calling is a bit slow because it processes a lot of data and that the server is hosted on cloudflare.

Expected Behavior

The HTTP POST request should somehow be sent only once

Steps to Reproduce

1) create an http request 2) before getting a feedback from the API, put the app in background 3) open and close the APP a few times

Code Reproduction URL

https://stackblitz.com/edit/angular-http-post-request-example

Ionic Info

`Ionic CLI : 7.2.0 Ionic Framework: @ionic/angular 7.7.2 @angular-devkit/build-angular : 15.2.10 @angular-devkit/schematics : 15.2.10 @angular/cli : 15.2.10
@ionic/angular-toolkit : 10.1.1

Capacitor:

Capacitor CLI : 5.7.0 @capacitor/android : 5.7.0 @capacitor/core : 5.7.0 @capacitor/ios : 5.7.0

Cordova:

Cordova CLI : 11.1.0 Cordova Platforms : not available Cordova Plugins : not available

Utility:

cordova-res : 0.15.4 native-run : 2.0.1

System:

NodeJS : v18.18.0 npm : 9.8.1 OS : macOS Unknown Xcode : Xcode 15.3 Build version 15E204a`

Additional Information

I can't really say when this issue exactly came up, it's probably there since a year though.

PS: I can't really give you a reproduction URL, the one i sent you it's just an example..

My package.json file:

"dependencies": { "@angular/common": "^15.2.9", "@angular/core": "^15.2.9", "@angular/forms": "^15.2.9", "@angular/platform-browser": "^15.2.9", "@angular/platform-browser-dynamic": "^15.2.9", "@angular/router": "^15.2.9", "@awesome-cordova-plugins/call-number": "6.3.0", "@awesome-cordova-plugins/core": "^6.3.0", "@awesome-cordova-plugins/email-composer": "6.3.0", "@awesome-cordova-plugins/fingerprint-aio": "6.3.0", "@awesome-cordova-plugins/firebase-dynamic-links": "6.3.0", "@awesome-cordova-plugins/in-app-browser": "6.3.0", "@capacitor-community/firebase-analytics": "4.0.0", "@capacitor-community/intercom": "^4.0.2", "@capacitor/android": "4.6.1", "@capacitor/app": "4.1.1", "@capacitor/camera": "4.1.4", "@capacitor/clipboard": "4.1.0", "@capacitor/core": "4.6.1", "@capacitor/device": "4.1.0", "@capacitor/haptics": "4.1.0", "@capacitor/ios": "4.6.1", "@capacitor/network": "4.1.0", "@capacitor/preferences": "4.0.2", "@capacitor/push-notifications": "^4.1.2", "@capacitor/share": "4.1.0", "@capacitor/splash-screen": "4.1.2", "@capacitor/status-bar": "4.1.1", "@dv-mobile-squad/dv-regex": "^0.0.3", "@ionic-native/market": "^5.36.0", "@ionic/angular": "^6.3.7", "@ionic/angular-toolkit": "9.0.0", "@schematics/angular": "15.2", "call-number": "^1.0.1", "chart.js": "^4.0.1", "cordova-plugin-email-composer": "^0.10.0", "cordova-plugin-fingerprint-aio": "^5.0.1", "cordova-plugin-firebase-dynamiclinks": "^7.0.2", "cordova-plugin-inappbrowser": "^5.0.0", "cordova-plugin-market": "^1.2.0", "cordova-support-android-plugin": "^2.0.4", "crypto-js": "^3.0.0", "es6-promise-plugin": "^4.2.2", "jumio-cordova-plugin-mobilesdk": "^3.9.2", "onesignal-cordova-plugin": "^3.3.1", "rxjs": "~6.6.3", "swiper": "^8.4.5", "tslib": "^2.5.3", "webpack-bundle-analyzer": "^4.9.0", "zone.js": "^0.12.0" }, "devDependencies": { "@angular-devkit/architect": "0.1502.8", "@angular-devkit/build-angular": "^15.2.8", "@angular-eslint/builder": "15.2.1", "@angular-eslint/eslint-plugin": "15.2.1", "@angular-eslint/eslint-plugin-template": "15.2.1", "@angular-eslint/schematics": "15.2.1", "@angular-eslint/template-parser": "15.2.1", "@angular/cli": "^15.2.8", "@angular/compiler": "^15.2.9", "@angular/compiler-cli": "^15.2.9", "@angular/language-service": "^15.2.9", "@capacitor/cli": "4.6.1", "@ionic/cli": "6.20.4", "@types/crypto-js": "^3.1.47", "@types/jasmine": "^4.3.2", "@types/jasminewd2": "^2.0.9", "@types/node": "^18.16.19", "@typescript-eslint/eslint-plugin": "5.48.2", "@typescript-eslint/parser": "5.48.2", "cordova-res": "0.15.4", "eslint": "^8.33.0", "jasmine-core": "^4.6.0", "jasmine-spec-reporter": "~7.0.0", "karma": "^6.4.2", "karma-chrome-launcher": "^3.2.0", "karma-coverage-istanbul-reporter": "^3.0.3", "karma-jasmine": "^5.1.0", "karma-jasmine-html-reporter": "^2.1.0", "ng-packagr": "^15.2.2", "ts-node": "^10.2.0", "typescript": "4.8.4" }

thetaPC commented 2 weeks ago

Thank you for submitting the issue!

However, we need a minimal repro that includes the Ionic Framework as part of the dependencies. The provided repro doesn't include it, which means that the issue is not related to Framework. Please provide a repro that showcases that Framework might be the issue.

ionitron-bot[bot] commented 2 weeks ago

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

thetaPC commented 2 weeks ago

I spoke with the team and we determined that this is outside the scope of Ionic Framework. The issue is most likely within the setup or within Angular or Capacitor. I recommend that you further investigate to determine where it's coming from and open an issue in the respective repository.