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

Using URLSession.backport.bytes(for:) causing crash #6

Open
alexanderwe opened this issue Jun 20, 2022 · 1 comment
Open

Using URLSession.backport.bytes(for:) causing crash #6

alexanderwe opened this issue Jun 20, 2022 · 1 comment

Comments

@alexanderwe
Copy link

alexanderwe commented Jun 20, 2022

First at all, thanks a lot for taking the time to create a library that backports the async/await versions of URLSession to iOS 14.

I am currently implementing some feature based on URLSession.bytes(for:) in my codebase. I still need to support iOS 14 and therefore found your library. In general the port works, but unfortunately not reliably. I often face crashes related to EXC_BAD_ACCESS or SIGABRT. When using an iOS 15 simulator, and therefore using the system provided methods the crash is not appearing,

I already tried to debug it a little, and it always crashes within the DataAccumulator. But at random places. Sometimes when data is added to the internal buffer or sometimes when reading from it. But the place seems to be random. I assume that there are some race conditions when the data receival is ending.

  • Maybe the .success case is already causing the data accumulator to be deallocated but another continuation is still running ?
  • Or maybe some other race condition is occuring, not sure unfortunately :/

Some examplary stack trace:

First Example

2022-06-20 21:03:10.358559+0200 URLSessionBackportTest[24786:502404] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
URLSessionBackportTest(24786,0x700007ae8000) malloc: Incorrect checksum for freed object 0x7f807c40f288: probably modified after being freed.
Corrupt value: 0xffffffe00000000
URLSessionBackportTest(24786,0x700007ae8000) malloc: *** set a breakpoint in malloc_error_break to debug
URLSessionBackportTest(24786,0x700007ae8000) malloc: Incorrect checksum for freed object 0x7f807c40f288: probably modified after being freed.
Corrupt value: 0xffffffe00000000
CoreSimulator 802.6.1 - Device: iPhone 8 Plus (250B5764-5BFD-440B-A918-82B557B5A993) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 8 Plus
(lldb) 

In the stack trace it can also be the seen where from the DataAccumulator this comes from:

Screenshot 2022-06-20 at 21 32 36

Second Example

2022-06-20 21:36:20.604135+0200 URLSessionBackportTest[26678:539387] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
URLSessionBackportTest(26678,0x70000a1da000) malloc: Incorrect checksum for freed object 0x7fe7d9905d18: probably modified after being freed.
Corrupt value: 0x2ffffffe00000000
URLSessionBackportTest(26678,0x70000a1da000) malloc: *** set a breakpoint in malloc_error_break to debug
URLSessionBackportTest(26678,0x70000a1da000) malloc: Incorrect checksum for freed object 0x7fe7d9905d18: probably modified after being freed.
Corrupt value: 0x2ffffffe00000000
CoreSimulator 802.6.1 - Device: iPhone 8 Plus (250B5764-5BFD-440B-A918-82B557B5A993) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 8 Plus
(lldb) 

Screenshot 2022-06-20 at 21 36 29

Third example

Screenshot 2022-06-20 at 21 37 59

I have also created a test repository which loads some image and also contains the kind of code I use the library with: https://github.com/alexanderwe/URLSessionBackportTest

Any help with that is highly appreciated !

@alexanderwe
Copy link
Author

alexanderwe commented Jun 21, 2022

I just enabled the ThreadSanitizer and it seems there are several places with some race conditions.

e.g.

  • Setting of the result in the DataAccumulator
  • Accessing the remainingByteBuffer

Screenshot 2022-06-21 at 10 19 26

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

No branches or pull requests

1 participant