HaishinKit.swift
HaishinKit.swift copied to clipboard
Crash at resize method call of Circular Buffer
Describe the bug
Getting app crashed while streaming
To Reproduce
random crash
Expected behavior
It shouldn't crash
Version
v: 1.3.0
Smartphone info.
iPhone SE (2nd Gen) iOS: 16.0.0
Additional context
Log from the Crashlytic
Crashed: com.haishinkit.HaishinKit.NetSocket.output
0 Foundation 0x41cacc Data.InlineSlice.replaceSubrange(:with:count:) + 224
1 Foundation 0x4239a4 Data.Representation.replaceSubrange(:with:count:) + 672
2 HaishinKit 0x62d04 NetSocket.CircularBuffer.resize((smiley) + 964 (<compiler-generated>:964)
3 HaishinKit 0x616e0 closure #2 in NetSocket.doOutput(data:locked:) + 104
4 HaishinKit 0x1ac5c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
5 libdispatch.dylib 0x24b4 _dispatch_call_block_and_release + 32
6 libdispatch.dylib 0x3fdc _dispatch_client_callout + 20
7 libdispatch.dylib 0xb694 _dispatch_lane_serial_drain + 672
8 libdispatch.dylib 0xc1e0 _dispatch_lane_invoke + 384
9 libdispatch.dylib 0x16e10 _dispatch_workloop_worker_thread + 652
10 libsystem_pthread.dylib 0xdf8 _pthread_wqthread + 288
11 libsystem_pthread.dylib 0xb98 start_wqthread + 8
Screenshots
No response
Relevant log output
Crashed: com.haishinkit.HaishinKit.NetSocket.output
0 Foundation 0x41cacc Data.InlineSlice.replaceSubrange(:with:count:) + 224
1 Foundation 0x4239a4 Data.Representation.replaceSubrange(:with:count:) + 672
2 HaishinKit 0x62d04 NetSocket.CircularBuffer.resize((smiley) + 964 (<compiler-generated>:964)
3 HaishinKit 0x616e0 closure #2 in NetSocket.doOutput(data:locked:) + 104
4 HaishinKit 0x1ac5c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
5 libdispatch.dylib 0x24b4 _dispatch_call_block_and_release + 32
6 libdispatch.dylib 0x3fdc _dispatch_client_callout + 20
7 libdispatch.dylib 0xb694 _dispatch_lane_serial_drain + 672
8 libdispatch.dylib 0xc1e0 _dispatch_lane_invoke + 384
9 libdispatch.dylib 0x16e10 _dispatch_workloop_worker_thread + 652
10 libsystem_pthread.dylib 0xdf8 _pthread_wqthread + 288
11 libsystem_pthread.dylib 0xb98 start_wqthread + 8
@ronhuang @pvinis @spllr @akolov Can anyone help me here I have to upload my build to Appstore. I will be very thankful you all
I have not used this lib in about 5 years. I would suggest you try the latest version (maybe it's fixed), then try to debug and see where that Data.InlineSlice thing is coming from and with what data (maybe you're doing something wrong), otherwise find another library or try to make your own library by understanding and copying things from this library here.
good luck.
usually crashes are not hat random once you investigate. try and test as little of your code as possible every time until you figure out if it's your code or the lib that's doing something wrong.
That's pretty much top 1 crash for us as well. Most of crashes happen when there's less than 100MB RAM left
I have the same problem.
I believe the range is out of bounds when calling replaceSubrange in some cases, thereby the crash on this line:
self.data.replaceSubrange(capacity - head..<capacity - head + subdata.count, with: subdata)
Specifically capacity - head + subdata.count
is larger than self.data.count
after calling skip
then resize
via append
.
First, application that is runnning device with iPhoneSE2, iPhon7, 8 and so on has a memory limit 2G. If your app’s memory usage is 1.90〜1.95G. And resize method call of Circular Buffer, may crash.
Workaround, you can use RTMPNWSocket by Network.framework.
rtmpConneciton.requireNetworkFramework = true
This class dose’t use a Circular Buffer. If memory limit is a factor, I think it will be replaced by another crash.
It seems necessary to not prevent buffer over run. Default buffer size is 65535 bytes. It is not enough recently.
I might want to consider to change BufferSize = (AudioBitrate + VideoBitrate) / 8 (in bytes)
Closes refs https://github.com/shogo4405/HaishinKit.swift/pull/1406