Instabug / Instabug-iOS

In-app feedback and bug reporting tool for apps.
https://instabug.com/
Other
290 stars 67 forks source link

Seeing a lot of API MISUSE messages in the console while running instabug network logging #443

Closed BrentMifsud closed 2 years ago

BrentMifsud commented 2 years ago

Steps to Reproduce the Problem

Enabled instabug network logging

Expected Behavior

Should not be seeing console log messages

Actual Behavior

2021-12-09 14:25:47.141795-0500 <MyApp>[2673:875842] API MISUSE: NSURLSession delegate IBGURLSessionDemux: <IBGURLSessionDemux: 0x281b2f4e0> (0x281b2f4e0)
2021-12-09 14:25:47.143581-0500 <MyApp>[2673:875842] API MISUSE: task:willPerformHTTPRedirection:newRequest:completionHandler: completion handler not called
2021-12-09 14:25:57.150380-0500 <MyApp>[2673:875842] API MISUSE: NSURLSession delegate IBGURLSessionDemux: <IBGURLSessionDemux: 0x281b2f4e0> (0x281b2f4e0)
2021-12-09 14:25:57.150770-0500 <MyApp>[2673:875842] API MISUSE: task:willPerformHTTPRedirection:newRequest:completionHandler: completion handler not called
2021-12-09 14:26:07.160213-0500 <MyApp>[2673:875842] API MISUSE: NSURLSession delegate IBGURLSessionDemux: <IBGURLSessionDemux: 0x281b2f4e0> (0x281b2f4e0)
2021-12-09 14:26:07.161453-0500 <MyApp>[2673:875842] API MISUSE: task:willPerformHTTPRedirection:newRequest:completionHandler: completion handler not called

Instabug integration code

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        setupInstabug()
        if let viewController = window?.rootViewController as? RootViewController {
            let baseURL = Environment.current.baseURL
            let apiToken = Environment.current.apiToken
            let urlSessionConfig = URLSessionConfiguration.default
            urlSessionConfig.timeoutIntervalForResource = 10

            // Prevent network cache from growing out of control
            // https://stackoverflow.com/questions/1330416/cfnetwork-memory-leaks-in-iphone
            urlSessionConfig.urlCache = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

            // Adds session to Instabug logger
            NetworkLogger.enableLogging(for: urlSessionConfig)

           // Some unrelated code...
        }

        // Some unrelated code...

        // Manually invoke Instabug when detecting bug report gesture
        instabugGestureObserver = NotificationCenter.default.addObserver(forName: .onBugReport, object: nil, queue: .main) { _ in
            Instabug.show()
        }

        return true
    }
    func setupInstabug() {
        // set up instabug
        Instabug.start(withToken: Constants.instabugToken, invocationEvents: [.none])
        Instabug.welcomeMessageMode = .disabled
        BugReporting.promptOptionsEnabledReportTypes = [.bug, .feedback]
        Replies.enabled = false
        // Also uploading the log because it goes beyond the last session
        Instabug.willSendReportHandler = { report in
            DDLog.flushLog()
            if let deviceId = UIDevice.current.identifierForVendor?.uuidString {
                Instabug.setUserAttribute(deviceId, withKey: "Device ID")
            }
            report.addFileAttachment(with: URL(fileURLWithPath: self.fileLogger?.currentLogFileInfo?.filePath ?? ""))
            if let logs = self.fileLogger?.logFileManager.sortedLogFilePaths, logs.count > 1 {
                Instabug.addFileAttachment(with: URL(fileURLWithPath: logs[1]))
            }
            return report
        }
        self.isInstabugActive = true
    }

SDK Version

10.11.0

iOS Version

15.1

Device Model

iPad

[Optional] Project That Reproduces the Issue

hassaanelgarem commented 2 years ago

We're looking into this. Can I ask if the redirected requests are failing or passing?

BrentMifsud commented 2 years ago

the redirects are going through.

But I did notice that while network logging is enabled, there seems to be a slight memory leak (about ~2 megabytes per hour) I did dive into instruments to take a look, I did see some references to IBGURLSessionDemux in there. Might be related to this.

Our app is an iPad kiosk that needs to run for long periods of time. And this was causing the app to kill itself after a week or so of runtime.

hassaanelgarem commented 2 years ago

Can you export the instruments trace and send it please? Or if not possible a screenshot of the leak could also be useful.

BrentMifsud commented 2 years ago

Can you export the instruments trace and send it please? Or if not possible a screenshot of the leak could also be useful.

Yea I can send one over.

Its not a huge leak. But over the course of a week or two it was causing our iPad app to kill itself from memory usage.

We did some tests on our end, removing the Network logging. No leak with Network logging disabled.

This was all on the latest version of instabug.

Here are some screenshots as well:

Screen Shot 2021-12-11 at 2 56 58 AM Screen Shot 2021-12-11 at 2 57 59 AM Screen Shot 2021-12-11 at 2 58 09 AM Screen Shot 2021-12-11 at 2 58 19 AM
BrentMifsud commented 2 years ago

@hassaanelgarem sent you a copy of the trace to the email you have on your GitHub profile.

hassaanelgarem commented 2 years ago

@BrentMifsud Thank you! We'll take a look and get back to you soon.

BrentMifsud commented 2 years ago

@BrentMifsud Thank you! We'll take a look and get back to you soon.

Great! thanks for looking into this.

husseinkishk commented 2 years ago

Hi @BrentMifsud, Would you please set this block -[IBGNetworkLogger setTaskWillPerformHTTPRedirectionBlock:] if your app attempting to perform a redirection to a different URL and you have network logging enabled. Regrading the memory leaks, We're still looking into it but could you please reproduce the leaks after passing your completionHandler to our API and send us the memory graph of the leaks.

BrentMifsud commented 2 years ago

@husseinkishk By adding that completion handler you mentioned above, the memory leak, and console messages are now gone.

I did export a memory graph before adding the completion handler that still has the leaks present. Do you have an email I can send it to? Id prefer not to dump my memory graph publicly on GitHub.

husseinkishk commented 2 years ago

@BrentMifsud I've the one you shared before to my colleague. Thank you.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

BrentMifsud commented 2 years ago

Bumping this to keep it open.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

ahmedsalah196 commented 2 years ago

@BrentMifsud I'm glad to inform you that this issue should be fixed on the latest version 10.11.4. I'd really like to thank you for opening this ticket which helped in increasing our SDK quality 🎉 I am closing this issue but feel free to reopen it if the issue persists 🙏