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

The app is frozen because it is in a loop #976

Closed
DevOpsAppsIOL opened this issue May 9, 2024 · 11 comments
Closed

The app is frozen because it is in a loop #976

DevOpsAppsIOL opened this issue May 9, 2024 · 11 comments
Assignees

Comments

@DevOpsAppsIOL
Copy link

Describe the bug
After updating the Prebid library from version 2.1.6 to major versions, when requested by the adv, the app is frozen.

The problem
I'm stuck in this loop:

- (nonnull NSString *)getFullUserAgent {
    if (self.userAgent == nil) {
        NSNumber *numberOfLoops = [NSNumber numberWithInt: 0];
        while (dispatch_semaphore_wait(self.uaSemaphore, DISPATCH_TIME_NOW + 1) && [numberOfLoops intValue] < 100) {
            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
                                     beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
            int value = [numberOfLoops intValue];
            numberOfLoops = [NSNumber numberWithInt:value + 1];
        }
    }
    return [NSString stringWithFormat:@"%@", self.userAgent ?: @""];
}

In older versions there was no while loop. but a simple:

- (nonnull NSString *)getFullUserAgent {
    return [NSString stringWithFormat:@"%@", self.userAgent];
}

Expected behavior
I expect there are no while loops blocking the entire application.

@hkimmgni
Copy link

@DevOpsAppsIOL , what version are you seeing this issue on? is it v2.2.1?

@jsligh
Copy link
Collaborator

jsligh commented May 17, 2024

@DevOpsAppsIOL This loop should still timeout and should never run infinitely. Where are you calling getFullUserAgent? It was implemented this way as there is a lot of multithreading in how the userAgent is found. The UserAgent has to be found on the main thread because WKWebView is used but the callbacks are on background threads but there has to be some waiting as there was no way around it.

@vgorloff
Copy link

vgorloff commented May 17, 2024

Same issue here. App just stuck and does nothing. Loop just blocks UI completely.
Would be nice if you will transform code to avoid synchronous operations, such as semaphores and / or custom "waiting logic".

We are on v.2.2.1-carthage.

Reverting to version 2.2.0-carthage resolved an issue.

@YuriyVelichkoPI
Copy link
Contributor

@OlenaPostindustria, could you please take a look at the issue when you have time?

@DevOpsAppsIOL
Copy link
Author

@DevOpsAppsIOL , what version are you seeing this issue on? is it v2.2.1?
Hi @jsligh,
I encountered the problem in versions 2.2.0 and 2.2.1.
I'm currently using 2.1.6 which doesn't give me any problems.
I'm waiting for a new version with the fix.
Thank you.

@YuriyVelichkoPI
Copy link
Contributor

YuriyVelichkoPI commented May 21, 2024

Hi @DevOpsAppsIOL et al

Please review the alternative implementation that should fix the issue: #983
The ua will still be present in each request.

This comment shows the time of fetching the ua.

All tests will pass once this PR for fixing the build of the Internal Test App and updating the supported GMA SDK version is merged.

@jsligh
Copy link
Collaborator

jsligh commented May 22, 2024

@DevOpsAppsIOL @vgorloff PrebidMobile version 2.2.2 has been released for iOS to fix this issue.

@vgorloff
Copy link

FYI: Tried to build v2.2.2 via Carthage, but got build failure 😮. See new issue – #985

@jsligh
Copy link
Collaborator

jsligh commented May 23, 2024

FYI: Tried to build v2.2.2 via Carthage, but got build failure 😮. See new issue – #985

@vgorloff apologies, was an error on my part. I pushed a fix, please try to build again.

@weibel
Copy link
Contributor

weibel commented May 29, 2024

There's something off with this. We're seeing a lot of crashes off the main thread in line 25 in UserAgentService private let webView = WKWebView(). WKWebView is supposed to run its init on main

      Crashed: PBMAdLoadFlowController_F13FBE0A-D142-4A42-949C-6D66A5725EC8
0  WebKit                         0x4fd8 <redacted> + 20
1  WebKit                         0x3139c8 <redacted> + 94
2  libc++.1.dylib                 0x13864 std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*)) + 180
3  WebKit                         0x3119e4 <redacted> + 84
4  WebKit                         0x41e6d4 <redacted> + 64
5  WebKit                         0x3df658 <redacted> + 56
6  PrebidMobile                   0xe46c8 @objc UserAgentService.init() + 25 (UserAgentService.swift:25)
7  PrebidMobile                   0xe43f4 one-time initialization function for shared + 21 (UserAgentService.swift:21)
8  libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
9  libdispatch.dylib              0x5654 _dispatch_once_callout + 32
10 PrebidMobile                   0xcf64c @objc PrebidServerConnection.init() + 21 (UserAgentService.swift:21)
11 PrebidMobile                   0xcd348 one-time initialization function for shared + 31 (PrebidServerConnection.swift:31)
12 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
13 libdispatch.dylib              0x5654 _dispatch_once_callout + 32
14 PrebidMobile                   0x74c5c closure #1 in BannerView.init(frame:configID:adSize:eventHandler:) + 31 (PrebidServerConnection.swift:31)
15 PrebidMobile                   0x78210 thunk for @escaping @callee_guaranteed (@guaranteed AdUnitConfig) -> (@owned PBMBidRequesterProtocol) + 48 (<compiler-generated>:48)
16 PrebidMobile                   0xbca4 -[PBMAdLoadFlowController sendBidRequest] + 214 (PBMAdLoadFlowController.m:214)
17 PrebidMobile                   0xbc00 -[PBMAdLoadFlowController tryLaunchingAdRequestFlow] + 208 (PBMAdLoadFlowController.m:208)
18 PrebidMobile                   0xb9b0 __34-[PBMAdLoadFlowController refresh]_block_invoke + 155 (PBMAdLoadFlowController.m:155)
19 PrebidMobile                   0xb890 __45-[PBMAdLoadFlowController enqueueGatedBlock:]_block_invoke + 144 (PBMAdLoadFlowController.m:144)
20 libdispatch.dylib              0x213c _dispatch_call_block_and_release + 32
21 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
22 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain + 748
23 libdispatch.dylib              0xbf30 _dispatch_lane_invoke + 380
24 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh + 288
25 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread + 404
26 libsystem_pthread.dylib        0x1f20 _pthread_wqthread + 288
27 libsystem_pthread.dylib        0x1fc0 start_wqthread + 8
    

@jsligh
Copy link
Collaborator

jsligh commented May 29, 2024

Created #988 to address.

@OlenaPostindustria @YuriyVelichkoPI can you please review #989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

6 participants