SwiftUI

[MacOS] [SwiftUI] Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9 오류 해결 방법

[오류내용]

2023-05-23 21:20:04.995335+0900 TestBackTask[26447:930433] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9’
*** First throw call stack:
(
0   CoreFoundation                      0x000000018fdc319c __exceptionPreprocess + 176
1   libobjc.A.dylib                     0x000000018f8e24d4 objc_exception_throw + 60
2   Foundation                          0x0000000190d2e324 -[NSConcreteTask launchWithDictionary:error:] + 4180
3   TestBackTask                  0x0000000100b21be0 $s18TestBackTask03getA5State33_490C33113C2A261E42B5066E2F2E00D4LLSaySSSgGyF + 736
4   TestBackTask                  0x0000000100b1fb00 $s18TestBackTask11ContentViewV05checkA0yyF + 636
5   TestBackTask                  0x0000000100b1f874 $s18TestBackTask11ContentViewV19startBackgroundTaskyyFyycfU_ySo7NSTimerCYbcfU_ + 44
6   TestBackTask                  0x0000000100b21838 $sSo7NSTimerCIeghg_ABIeyBhy_TR + 64
7   Foundation                          0x0000000190cf9538 __NSFireTimer + 104
8   CoreFoundation                      0x000000018fd6448c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
9   CoreFoundation                      0x000000018fd64134 __CFRunLoopDoTimer + 940
10  CoreFoundation                      0x000000018fd63c8c __CFRunLoopDoTimers + 356
11  CoreFoundation                      0x000000018fd4941c __CFRunLoopRun + 1852
12  CoreFoundation                      0x000000018fd4858c CFRunLoopRunSpecific + 612
13  Foundation                          0x0000000190cc10bc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
14  Foundation                          0x0000000190d39dbc -[NSRunLoop(NSRunLoop) run] + 64
15  TestBackTask                  0x0000000100b1f830 $s18TestBackTask11ContentViewV19startBackgroundTaskyyFyycfU_ + 876
16  TestBackTask                  0x0000000100b1e2c0 $sIeg_IeyB_TR + 48
17  libdispatch.dylib                   0x000000010106a99c _dispatch_client_callout + 20
18  libdispatch.dylib                   0x000000010106e274 _dispatch_continuation_pop + 816
19  libdispatch.dylib                   0x0000000101089584 _dispatch_source_invoke + 1724
20  libdispatch.dylib                   0x0000000101082908 _dispatch_root_queue_drain + 408
21  libdispatch.dylib                   0x000000010108352c _dispatch_worker_thread2 + 196
22  libsystem_pthread.dylib             0x0000000100c6fc8c _pthread_wqthread + 228
23  libsystem_pthread.dylib             0x0000000100c77a6c start_wqthread + 8
)
2023-05-23 21:20:04.996681+0900 TestBackTask[26447:930433] [General] An uncaught exception was raised
2023-05-23 21:20:04.997024+0900 TestBackTask[26447:930433] [General] Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9
2023-05-23 21:20:04.997441+0900 TestBackTask[26447:930433] [General] (
0   CoreFoundation                      0x000000018fdc319c __exceptionPreprocess + 176
1   libobjc.A.dylib                     0x000000018f8e24d4 objc_exception_throw + 60
2   Foundation                          0x0000000190d2e324 -[NSConcreteTask launchWithDictionary:error:] + 4180
3   TestBackTask                  0x0000000100b21be0 $s18TestBackTask03getA5State33_490C33113C2A261E42B5066E2F2E00D4LLSaySSSgGyF + 736
4   TestBackTask                  0x0000000100b1fb00 $s18TestBackTask11ContentViewV05checkA0yyF + 636
5   TestBackTask                  0x0000000100b1f874 $s18TestBackTask11ContentViewV19startBackgroundTaskyyFyycfU_ySo7NSTimerCYbcfU_ + 44
6   TestBackTask                  0x0000000100b21838 $sSo7NSTimerCIeghg_ABIeyBhy_TR + 64
7   Foundation                          0x0000000190cf9538 __NSFireTimer + 104
8   CoreFoundation                      0x000000018fd6448c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
9   CoreFoundation                      0x000000018fd64134 __CFRunLoopDoTimer + 940
10  CoreFoundation                      0x000000018fd63c8c __CFRunLoopDoTimers + 356
11  CoreFoundation                      0x000000018fd4941c __CFRunLoopRun + 1852
12  CoreFoundation                      0x000000018fd4858c CFRunLoopRunSpecific + 612
13  Foundation                          0x0000000190cc10bc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
14  Foundation                          0x0000000190d39dbc -[NSRunLoop(NSRunLoop) run] + 64
15  TestBackTask                  0x0000000100b1f830 $s18TestBackTask11ContentViewV19startBackgroundTaskyyFyycfU_ + 876
16  TestBackTask                  0x0000000100b1e2c0 $sIeg_IeyB_TR + 48
17  libdispatch.dylib                   0x000000010106a99c _dispatch_client_callout + 20
18  libdispatch.dylib                   0x000000010106e274 _dispatch_continuation_pop + 816
19  libdispatch.dylib                   0x0000000101089584 _dispatch_source_invoke + 1724
20  libdispatch.dylib                   0x0000000101082908 _dispatch_root_queue_drain + 408
21  libdispatch.dylib                   0x000000010108352c _dispatch_worker_thread2 + 196
22  libsystem_pthread.dylib             0x0000000100c6fc8c _pthread_wqthread + 228
23  libsystem_pthread.dylib             0x0000000100c77a6c start_wqthread + 8
)
libc++abi: terminating due to uncaught exception of type NSException

[로그 모니터링]

백그라운드 서비스에서 멈추지않고 잘 돌아가는지 체크하기 위해 로그를 찍었다.

################ startBackgroundTask
2023-05-23 19:00:18 :percent--> 68% 시작
2023-05-23 19:00:19 :percent--> 69%
2023-05-23 19:00:19 :percent--> 69%
2023-05-23 19:00:21 :percent--> 69%
2023-05-23 19:00:22 :percent--> 69%
2023-05-23 19:00:23 :percent--> 69%
2023-05-23 19:00:23 :percent--> 69%
2023-05-23 19:00:25 :percent--> 69%
          ~~~생략~~~ 
2023-05-23 19:41:00 :percent--> 98%
2023-05-23 19:41:01 :percent--> 98%
2023-05-23 19:41:02 :percent--> 98%
2023-05-23 19:41:03 :percent--> 98%
2023-05-23 19:41:04 :percent--> 98%
2023-05-23 19:41:05 :percent--> 98%
2023-05-23 19:41:06 :percent--> 98%
2023-05-23 19:41:07 :percent--> 98%
2023-05-23 19:41:08 :percent--> 98%
2023-05-23 19:41:09 :percent--> 98%
2023-05-23 19:41:10 :percent--> 98%
2023-05-23 19:41:11 :percent--> 98%
2023-05-23 19:41:12 :percent--> 98%
2023-05-23 19:41:13 :percent--> 98%
2023-05-23 19:41:14 :percent--> 98%
2023-05-23 19:41:15 :percent--> 98%
2023-05-23 19:41:16 :percent--> 98%
2023-05-23 19:41:17 :percent--> 98%
2023-05-23 19:41:18 :percent--> 98%
2023-05-23 19:41:19 :percent--> 98%
2023-05-23 19:41:20 :percent--> 98%
2023-05-23 19:41:21 :percent--> 98%
2023-05-23 19:41:22 :percent--> 98%
2023-05-23 19:41:23 :percent--> 98%
2023-05-23 19:41:24 :percent--> 98%
2023-05-23 19:41:25 :percent--> 98%
2023-05-23 19:41:26 :percent--> 98%
2023-05-23 19:41:27 :percent--> 98%
2023-05-23 19:41:28 :percent--> 98%
2023-05-23 19:41:29 :percent--> 98%
2023-05-23 19:41:30 :percent--> 98%
2023-05-23 19:41:31 :percent--> 98%
2023-05-23 19:41:32 :percent--> 98%
2023-05-23 19:41:33 :percent--> 98%
2023-05-23 19:41:34 :percent--> 98%
2023-05-23 19:41:35 :percent--> 98%
2023-05-23 19:41:36 :percent--> 98%
2023-05-23 19:41:37 :percent--> 98%
2023-05-23 19:41:38 :percent--> 98%
2023-05-23 19:41:39 :percent--> 98%
2023-05-23 19:41:40 :percent--> 98%
2023-05-23 19:41:41 :percent--> 98%
2023-05-23 19:41:42 :percent--> 98%
2023-05-23 19:41:43 :percent--> 98%
2023-05-23 19:41:44 :percent--> 98%
2023-05-23 19:41:45 :percent--> 98%
2023-05-23 19:41:46 :percent--> 98%
2023-05-23 19:41:47 :percent--> 98%
2023-05-23 19:41:48 :percent--> 98%
2023-05-23 19:41:49 :percent--> 98%
2023-05-23 19:41:50 :percent--> 98%
2023-05-23 19:41:51 :percent--> 98%
2023-05-23 19:41:52 :percent--> 98%
2023-05-23 19:41:53 :percent--> 98%
2023-05-23 19:41:54 :percent--> 98%
2023-05-23 19:41:55 :percent--> 98%
2023-05-23 19:41:56 :percent--> 98%
2023-05-23 19:41:57 :percent--> 98%
2023-05-23 19:41:58 :percent--> 98%
2023-05-23 19:41:59 :percent--> 98%
2023-05-23 19:42:00 :percent--> 98%
2023-05-23 19:42:01 :percent--> 98%
2023-05-23 19:42:02 :percent--> 98%
2023-05-23 19:42:04 :percent--> 98%
2023-05-23 19:42:04 :percent--> 98%
2023-05-23 19:42:05 :percent--> 98%
2023-05-23 19:42:07 :percent--> 98%
2023-05-23 19:42:07 :percent--> 98%
2023-05-23 19:42:08 :percent--> 98%

     42분간 1초에서 3초 간격으로 잘 동작함

2023-05-23 20:00:02 :percent--> 98%
2023-05-23 20:00:03 :percent--> 98%
2023-05-23 20:00:04 :percent--> 98%
2023-05-23 20:00:06 :percent--> 98%
2023-05-23 20:00:07 :percent--> 98%
2023-05-23 20:00:08 :percent--> 98%
2023-05-23 20:15:07 :percent--> 98%
2023-05-23 20:15:08 :percent--> 98%
2023-05-23 20:15:09 :percent--> 98%
2023-05-23 20:15:10 :percent--> 98%
2023-05-23 20:15:11 :percent--> 98%
2023-05-23 20:15:12 :percent--> 98%
2023-05-23 20:30:15 :percent--> 98%
2023-05-23 20:30:16 :percent--> 98%
2023-05-23 20:30:17 :percent--> 98%
2023-05-23 20:30:18 :percent--> 98%
2023-05-23 20:30:19 :percent--> 98%
2023-05-23 20:30:20 :percent--> 98%
2023-05-23 20:47:37 :percent--> 98%
2023-05-23 20:47:38 :percent--> 98%
2023-05-23 20:47:39 :percent--> 98%
2023-05-23 20:47:38 :percent--> 98%
2023-05-23 20:47:39 :percent--> 98%
2023-05-23 20:47:40 :percent--> 98%
2023-05-23 20:47:41 :percent--> 98%
2023-05-23 21:03:35 :percent--> 98%
2023-05-23 21:03:36 :percent--> 98%
2023-05-23 21:03:37 :percent--> 98%
2023-05-23 21:03:38 :percent--> 98%
2023-05-23 21:03:39 :percent--> 98%
2023-05-23 21:03:40 :percent--> 98%
2023-05-23 21:20:03 :percent--> 98%
2023-05-23 21:20:04 :percent--> 98%

42분간은 1초에서 3초간격으로 로깅이 되었고, 맥북이 잠자기모드로 전환된건지 슬립모드로 전환된건지는 모르겠지만

호출간격 시간이었던 1초간격은 무시되었고, 

18분 뒤 호출되었다. 

그리고 다음 호출로 15분 뒤 호출, 15분 뒤 호출, 17분뒤 호출, 16분뒤 호출 , 17분 뒤 호출 후 서비스가 죽었다.

슬립모드에 들어가서 그런건가?

 

[테스트 코드]

백그라운드에서 1초간격으로 호출 테스트 코드

print("################ startBackgroundTask")
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 3) { //global(qos: .utility)
        let runLoop = RunLoop.current
        timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in

//                    DispatchQueue.main.async {
                checkTask()
//                    }
        }

    // Run the timer on the current run loop
//            RunLoop.current.add(timer!, forMode: .common)
    runLoop.add(timer!, forMode: .default)
    runLoop.run()

func checkTask() {
	remaing = "remaing--> (content[3])"
    
    print("(nowDate) :percent--> (content[2])%")

}
@State private var remaing = ""
@State var timer: Timer? 

@Environment(.colorScheme) var colorScheme
@Environment(.scenePhase) var scenePhase

var body: some View {
    VStack {
                Text(remaing)
    }
}

[오류 해결]

DispatchQueue.main.async 로 감싸주고 다시 테스트를 진행중이다.

DispatchQueue.main.async {
	checkTask()
}

멈추지 않고 잘 된다면, 반쪽자리 프로그램에서 벗어날 수 있을 것 같다.

Leave a Reply

error: Content is protected !!