soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
878 stars 83 forks source link

EXC_BAD_ACCESS KERN_PROTECTION_FAILURE during s3FileTransferManager.copy #662

Closed andrew-xue97 closed 1 year ago

andrew-xue97 commented 1 year ago

Encountered EXC_BAD_ACCESS during s3FileTransferManager.copy(from: {local_uri}, to: S3File(url: {dest_uri}))

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016e073fd0
Exception Codes: 0x0000000000000002, 0x000000016e073fd0
VM Region Info: 0x16e073fd0 is in 0x16e070000-0x16e074000;  bytes after start: 16336  bytes before end: 47
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      Stack                    16dfe8000-16e070000 [  544K] rw-/rwx SM=PRV  thread 6
--->  STACK GUARD              16e070000-16e074000 [   16K] ---/rwx SM=NUL  ... for thread 7
      Stack                    16e074000-16e0fc000 [  544K] rw-/rwx SM=PRV  thread 7
Termination Reason: SIGNAL 10 Bus error: 10
Terminating Process: exc handler [90677]

Setup (please complete the following information):

To Reproduce

Thread 7 name:   Dispatch queue: nio.nioTransportServices.connectionchannel
Thread 7 Crashed:
0   libsystem_c.dylib                      0x1bc7ba498 __sfvwrite + 4
1   libsystem_c.dylib                      0x1bc7b3c40 __vfprintf + 7200
2   libsystem_c.dylib                      0x1bc7b1e04 _vsnprintf + 224
3   libsystem_c.dylib                      0x1bc7b5d48 snprintf_l + 32
4   CoreFoundation                         0x1b519c1b4 __CFStringAppendFormatCore + 10420
5   CoreFoundation                         0x1b51d0c04 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 184
6   CoreFoundation                         0x1b51cd570 _CFStringCreateWithFormatAndArgumentsAux2 + 44
7   Foundation                             0x1af898338 NSString.__allocating_init(format:locale:arguments:) + 336
8   Foundation                             0x1af89f1e4 specialized withVaList<A>(_:_:) + 532
9   Foundation                             0x1af89a3bc String.init(format:_:) + 68
10  XXmyAppXX                          0x1053d605c specialized Sequence<>.hexDigest() + 268
11  XXmyAppXX                          0x1053e16f4 specialized static AWSSigner.hashedPayload(_:) + 540
12  XXmyAppXX                          0x1053da9ac AWSSigner.chunkStringToSign(body:previousSignature:datetime:) + 880
13  XXmyAppXX                      0x1053da4c4 AWSSigner.signChunk(body:signingData:) + 64
14  XXmyAppXX                          0x1052d5d74 closure #1 in S3ChunkedStreamReader.streamChunks(on:) + 168
15  XXmyAppXX                          0x1052d632c partial apply for thunk for @escaping @callee_guaranteed (@guaranteed ByteBuffer) -> (@owned [ByteBuffer]) + 52
16  XXmyAppXX                          0x105269b74 specialized closure #1 in EventLoopFuture.map<A>(_:) + 140
17  XXmyAppXX                          0x10525def8 specialized EventLoopFuture.map<A>(_:) + 544
18  XXmyAppXX                          0x1052d5ca4 S3ChunkedStreamReader.streamChunks(on:) + 120
19  XXmyAppXX                          0x1052d62bc protocol witness for StreamReader.streamChunks(on:) in conformance S3ChunkedStreamReader + 20
20  XXmyAppXX                          0x1052d8828 specialized closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 116
21  XXmyAppXX                          0x1052d86fc partial apply for closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 36
22  XXmyAppXX                          0x1052d7bb0 specialized closure #1 in EventLoopFuture.flatMap<A>(_:) + 84
23  XXmyAppXX                          0x1052d7f50 specialized EventLoopFuture.flatMap<A>(_:) + 364
24  XXmyAppXX                          0x1052d7920 closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 516
25  XXmyAppXX                          0x1052d7b50 partial apply for closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 44
26  XXmyAppXX                          0x1052d8214 specialized EventLoopFuture.map<A>(_:) + 388
27  XXmyAppXX                          0x1052d889c specialized closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 232
28  XXmyAppXX                          0x1052d86fc partial apply for closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 36
29  XXmyAppXX                          0x1052d7bb0 specialized closure #1 in EventLoopFuture.flatMap<A>(_:) + 84
30  XXmyAppXX                          0x1052d7f50 specialized EventLoopFuture.flatMap<A>(_:) + 364
...
...
504 XXmyAppXX                          0x1052d86fc partial apply for closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 36
505 XXmyAppXX                          0x1052d7bb0 specialized closure #1 in EventLoopFuture.flatMap<A>(_:) + 84
506 XXmyAppXX                          0x1052d7f50 specialized EventLoopFuture.flatMap<A>(_:) + 364
507 XXmyAppXX                          0x1052d7920 closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 516
508 XXmyAppXX                          0x1052d7b50 partial apply for closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 44
509 XXmyAppXX                          0x1052d8214 specialized EventLoopFuture.map<A>(_:) + 388
510 XXmyAppXX                          0x1052d889c specialized closure #3 in closure #1 in _write #1 (_:) in HTTPClient.Body.StreamWriter.write(reader:on:) + 232

Additional context The crash was only reported by one user. I was not able to reproduce the crash myself. The Stack trace pointed me to AWSSigner in SOTO, therefore trying to seek help here for some clue. Thanks!

adam-fowler commented 1 year ago

This looks like a stack overflow. If you could post the full stack that'd be great

andrew-xue97 commented 1 year ago

Thanks for your prompt reply. Unfortunately that's as far as the faulty thread trace goes back.

Here's some extra info in the crash log. Please let me email you the full log if that helps. Thanks! `Thread 7 crashed with ARM Thread State (64-bit): x0: 0x000000016e074428 x1: 0x000000016e074158 x2: 0x0000000000000010 x3: 0x0000000000000000 x4: 0x00000001c588fb8f x5: 0x000000016e0745e0 x6: 0x000000016e0745e0 x7: 0x000000016e0750b4 x8: 0x0000000000000002 x9: 0x0000000000000000 x10: 0x0000000000000001 x11: 0x0000000000000002 x12: 0x0000000000000002 x13: 0x0000000000000078 x14: 0x0000000000000000 x15: 0x000000016e075840 x16: 0x00000001c58178a0 x17: 0x00000001c5817294 x18: 0x0000000000000000 x19: 0x000000000000000a x20: 0x000000016e074316 x21: 0x0000000000000002 x22: 0x0000000000000002 x23: 0x0000000000000002 x24: 0x00000000fffffffd x25: 0x0000000000000080 x26: 0x0000000000000000 x27: 0x000000016e074a64 x28: 0x0000000000000010 fp: 0x000000016e074410 lr: 0xd63d8001c5818c40 sp: 0x000000016e074030 pc: 0x00000001c581f498 cpsr: 0x80001000 far: 0x000000016e073fd0 esr: 0x92000047 (Data Abort) byte write Translation fault

Binary Images: 0x1fadf9000 - 0x1fae2fffb libsystem_kernel.dylib arm64e /usr/lib/system/libsystem_kernel.dylib 0x1be1f8000 - 0x1be5ddfff CoreFoundation arm64e <5cdc5d9ae5063740b64ebb30867b4f1b> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 0x1f7579000 - 0x1f7581fff GraphicsServices arm64e /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices 0x1c03b5000 - 0x1c1b92fff UIKitCore arm64e <179501b60fc2344ab969b4e3961ebe10> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore 0x1c1b93000 - 0x1c34d6fff SwiftUI arm64e <494a7d5790af3e9096237038275b8d87> /System/Library/Frameworks/SwiftUI.framework/SwiftUI 0x102ab0000 - 0x10338ffff XXmyAppXX arm64 /private/var/containers/Bundle/Application/419B65DB-2E94-47FA-928B-DA6E2B6B65EC/XXmyAppXX.app/XXmyAppXX 0x1dc8cf000 - 0x1dc95200f dyld arm64e /usr/lib/dyld 0x1b85d8000 - 0x1b8f21fff Foundation arm64e /System/Library/Frameworks/Foundation.framework/Foundation 0x20b25b000 - 0x20b266fff libsystem_pthread.dylib arm64e <1aa3a4b6f9e730568c8b4e4dd81312a4> /usr/lib/system/libsystem_pthread.dylib 0x1bf37a000 - 0x1bf741fff CFNetwork arm64e /System/Library/Frameworks/CFNetwork.framework/CFNetwork 0x1be5de000 - 0x1bf379fff Network arm64e <3bf445f9d58f3280b9c92feaf4daca6d> /System/Library/Frameworks/Network.framework/Network 0x21f24a000 - 0x21f2b5ffe libusrtcp.dylib arm64e <003f82647e7233cebfe6a8adb3152e99> /usr/lib/libusrtcp.dylib 0x1e799b000 - 0x1e7a5cfff libboringssl.dylib arm64e <00b7ff4a3b383877bcd3016caf775740> /usr/lib/libboringssl.dylib 0x1c57ce000 - 0x1c5814fff libdispatch.dylib arm64e /usr/lib/system/libdispatch.dylib 0x1c5815000 - 0x1c5894ff7 libsystem_c.dylib arm64e /usr/lib/system/libsystem_c.dylib 0x0 - 0xffffffffffffffff ??? unknown-arch <00000000000000000000000000000000> ???`

adam-fowler commented 1 year ago

I have a possible fix here https://github.com/soto-project/soto-core/pull/538 This should remove the possible chance of a stack overflow when streaming data.

adam-fowler commented 1 year ago

This has now been released in https://github.com/soto-project/soto-core/releases/tag/6.4.2 If you do a swift package update it should be fixed.