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

[Bug]: iOS crash in Http Plugin #7404

Closed
1 of 3 tasks
JosefBredereck opened this issue Apr 16, 2024 · 13 comments · Fixed by #7482
Closed
1 of 3 tasks

[Bug]: iOS crash in Http Plugin #7404

JosefBredereck opened this issue Apr 16, 2024 · 13 comments · Fixed by #7482
Labels
platform: ios type: bug A confirmed bug report

Comments

@JosefBredereck
Copy link

JosefBredereck commented Apr 16, 2024

Capacitor Version

Config: {
  appId: 'de.company.appid.mobile',
  appName: 'App Name',
  webDir: 'dist/apps/app/browser',
  backgroundColor: '#003399',
  loggingBehavior: 'none',
  android: {
    path: './native/android',
    webContentsDebuggingEnabled: false
  },
  ios: {
    path: './native/ios',
    webContentsDebuggingEnabled: false
  },
  server: { androidScheme: 'https' },
  includePlugins: [
    '@capacitor/app',
    '@capacitor/browser',
    '@capacitor/device',
    '@capacitor/filesystem',
    '@capacitor/keyboard',
    '@capacitor/network',
    '@capacitor/preferences',
    '@capacitor/splash-screen',
    '@capacitor/camera',
  ],
  plugins: {
    Keyboard: { resize: 'none' },
    SplashScreen: {
      launchShowDuration: 700,
      launchAutoHide: true,
      androidScaleType: 'CENTER_INSIDE',
      backgroundColor: '#1a3691'
    },
    CapacitorHttp: { enabled: true }
  }
}

💊 Capacitor Doctor 💊

Latest Dependencies:

  @capacitor/cli: 6.0.0
  @capacitor/core: 6.0.0
  @capacitor/android: 6.0.0
  @capacitor/ios: 6.0.0

Installed Dependencies:

  @capacitor/cli: 5.6.0
  @capacitor/core: 5.7.4
  @capacitor/android: 5.7.4
  @capacitor/ios: 5.7.4

Other API Details

npm: 10.2.4
node: v21.6.1

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

We observed an issue on iOS. At random, the app crashes in an Angular application when requests are fired and aborted.
The question remains what exactly causes the issue, we could not create a successful reproduction. Sometimes it happens when a request gets unsubscribed (aborted) and sometimes when the request resolves with an error.

scheme stop
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This task has already been stopped'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000111da7761 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x000000010d3e3904 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000111da763f -[NSException initWithCoder:] + 0
	3   WebKit                              0x000000010e042658 -[WKURLSchemeTaskImpl didReceiveResponse:] + 141
	4   Capacitor                           0x000000010a05272d $s9Capacitor19WebViewAssetHandlerC06handleA11HttpRequestyySo15WKURLSchemeTask_p_10Foundation3URLVSbtFyAF4DataVSg_So13NSURLResponseCSgs5Error_pSgtYbcfU_ + 2621
	5   Capacitor                           0x000000010a0529bd $s9Capacitor19WebViewAssetHandlerC06handleA11HttpRequestyySo15WKURLSchemeTask_p_10Foundation3URLVSbtFyAF4DataVSg_So13NSURLResponseCSgs5Error_pSgtYbcfU_TA + 93
	6   Capacitor                           0x000000010a01d60c $s10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIeghggg_So6NSDataCSgAGSo7NSErrorCSgIeyBhyyy_TR + 252
	7   CFNetwork                           0x000000010f728698 CFNetwork + 38552
	8   CFNetwork                           0x000000010f7461b1 _CFHTTPMessageSetResponseProxyURL + 16951
	9   libdispatch.dylib                   0x0000000113092747 _dispatch_call_block_and_release + 12
	10  libdispatch.dylib                   0x00000001130939f7 _dispatch_client_callout + 8
	11  libdispatch.dylib                   0x000000011309b8c9 _dispatch_lane_serial_drain + 1127
	12  libdispatch.dylib                   0x000000011309c665 _dispatch_lane_invoke + 441
	13  libdispatch.dylib                   0x00000001130a976e _dispatch_root_queue_drain_deferred_wlh + 318
	14  libdispatch.dylib                   0x00000001130a8b69 _dispatch_workloop_worker_thread + 590
	15  libsystem_pthread.dylib             0x00000001158aeb84 _pthread_wqthread + 327
	16  libsystem_pthread.dylib             0x00000001158adacf start_wqthread + 15
)
libc++abi: terminating due to uncaught exception of type NSException

The actual position where the crash happens is

urlSchemeTask.didReceive(modifiedResponse)

Based on https://stackoverflow.com/a/73581176 a possible solution could be to not abort the request like you would in the web environment.

Maybe the solution Flutter has implemented could give a possible direction:
https://github.com/arnaudelub/flutter_polywebview/blob/76def884f29ac13065a538a10789b761c168c5ff/ios/Classes/CustomeSchemeHandler.swift

Expected Behavior

The app does not do a hard crash.

Project Reproduction

Repo: capacitor-issue-7404

Additional Information

No response

@JosefBredereck JosefBredereck changed the title [Bug]: [Bug]: iOS crash in Http Plugin Apr 16, 2024
@foo-cb
Copy link

foo-cb commented Apr 17, 2024

Can confirm. We're getting the same error when requests get aborted.

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Apr 23, 2024
Copy link

ionitron-bot bot commented Apr 23, 2024

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 💙

@ionitron-bot ionitron-bot bot removed the triage label Apr 23, 2024
@Ionitron Ionitron added needs reply needs reply from the user and removed needs reply needs reply from the user labels Apr 23, 2024
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Apr 23, 2024
@patrickjquinn
Copy link

Aborted requests also cause hard crashes on iOS, have had to fully disable the HTTP plugin.

If you want to reproduce, create a very simple project with CapacitorHTTP wrapping true in the config + Axios + AxiosAbortSignals

If you make a request and then cancel it using a signal you get a crash with the error message referring to the fact the request is already cancelled.

I've noticed a ton of instability with the CapHTTP plugin in the last couple of releases so it may be an area that needs a bit of love and maybe bolstered testing.

@Ionitron Ionitron removed the needs reply needs reply from the user label Apr 24, 2024
@JosefBredereck
Copy link
Author

I created a simple reproduction repository: https://github.com/JosefBredereck/capacitor-issue-7404
Just run npm run build:cap and click the red button.

@jcesarmobile jcesarmobile added type: bug A confirmed bug report and removed needs reproduction needs reproducible example to illustrate the issue labels Apr 30, 2024
Copy link

ionitron-bot bot commented Apr 30, 2024

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

@SergioMartinSanchez
Copy link

Hello! we have the same problem, this prevents us from using the http plugin completely.

@joelfbarber
Copy link

We are also running into this same problem.

@ZairKSM
Copy link

ZairKSM commented May 2, 2024

Hello , We have the same problem. Does deactivating the http plugin temporarily solve your problem?

@ZairKSM
Copy link

ZairKSM commented May 4, 2024

Hello @JosefBredereck
I managed to avoid the hard crash of the APP and get an error more detailed by doing this :

I created the following file in @capacitor/ios/Capacitor/Capacitor folder, This file is used to handle the error correctly

//
//  ExceptionCatcher.h
//

#import <Foundation/Foundation.h>

NS_INLINE NSException * _Nullable tryBlock(void(^_Nonnull tryBlock)(void)) {
    @try {
        tryBlock();
    }
    @catch (NSException *exception) {
        return exception;
    }
    return nil;
}

In the same folder, I've modified the Capacitor.h file and added an import to the new file I've just created, to make it available in the swift code.

Just add #import <Capacitor/ExceptionCatcher.h> to the end of the file.

#import <UIKit/UIKit.h>
//! Project version number for bridge.
FOUNDATION_EXPORT double CapacitorVersionNumber;
//! Project version string for bridge.
FOUNDATION_EXPORT const unsigned char CapacitorVersionString[];
#import <Capacitor/CAPPlugin.h>
#import <Capacitor/CAPPluginCall.h>
#import <Capacitor/CAPBridgedPlugin.h>
#import <Capacitor/CAPPluginMethod.h>
#import <Capacitor/CAPInstanceDescriptor.h>
#import <Capacitor/CAPInstanceConfiguration.h>

I then modified these 3 calls by putting them in a tryBlock()

urlSchemeTask.didReceive(modifiedResponse)

urlSchemeTask.didReceive(data)

Like this :

let exception = tryBlock {
   urlSchemeTask.didReceive(data)
}

In my case it gives me this error:

[assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
2024-05-04 21:37:26.046048+0200 App[40914:671298] [ProcessSuspension] 0x10f020480 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=40922, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
2024-05-04 21:37:26.070055+0200 App[40914:671298] [assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
2024-05-04 21:37:26.070132+0200 App[40914:671298] [ProcessSuspension] 0x10f0207e0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=40921, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
2024-05-04 21:37:26.071127+0200 App[40914:671298] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
2024-05-04 21:37:26.071177+0200 App[40914:671298] [ProcessSuspension] 0x10f020ba0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess Suspended Assertion' for process with PID=40921, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
2024-05-04 21:37:56.026363+0200 App[40914:670854] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
2024-05-04 21:37:56.050115+0200 App[40914:670854] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

I hope I've made myself clear. This avoids the hard crash but in my case I'm looking for a better way to correct it.

@JosefBredereck
Copy link
Author

I would like to prevent the modification of remote files in my project. I appreciate the idea but it's not sufficient for our project.

@ZairKSM
Copy link

ZairKSM commented May 4, 2024

I'd also like to avoid doing it, but I was able to get more details from my error. In my case, it happens when I close my inappbrowser window from @awesome-cordova-plugins/in-app-browser.

@cstriuli
Copy link

cstriuli commented May 7, 2024

same error, any update about this? ty

Copy link

ionitron-bot bot commented Jun 23, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jun 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.