Post

Replies

Boosts

Views

Activity

`BUG IN CLIENT OF LIBMALLOC: memory corruption of free block` crash at `AbstractCombineLatest.request(_:) ()`
Hello! I am running into a crash at AbstractCombineLatest.request(_:) (), BUG IN CLIENT OF LIBMALLOC: memory corruption of free block. The crash is Crashed: com.apple.NSURLSession-delegate EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000, or Crashed: com.apple.NSURLSession-delegate EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x446d4644951e0518 This has only been reported in production, for a small percentage of users. It has been present in our application for a while, but has become much more prevalent in the past few weeks, coinciding with the iOS 18.5 release. The crash occurs when sending a value fetched from a network to a CurrentValueSubject, which is done on a Timer. A skeleton of the timer creation function: private func newTimer(for url: URL) { timerCancellable?.cancel() timerCancellable = Timer .publish(every: interval, on: .current, in: .common) .autoconnect() .flatMap({ [weak self] _ -> AnyPublisher<Response?, Never> in guard let self = self else { return Just(nil).eraseToAnyPublisher() } return self.fetch(from: url) }) .sink(receiveValue: { response in self.subject.send(response) // Crash occurs here }) } and the network request: private func fetch(from url: URL) -> AnyPublisher<Response?, Never> { return session .dataTaskPublisher(for: url) .map { (data, response) in let response = try? JSONDecoder().decode(Response.self, from: data) return response } .replaceError(with: nil) .eraseToAnyPublisher() } Timer creation itself is triggered by a separate publisher: otherPublisher .map({ item in guard let url = item?.url else { self.timerCancellable?.cancel() return nil } self.newTimer(for: url) return url }) ... Our crash reporting system has indicated the majority of these occur in the background, so I am curious if something could have changed in iOS 18.5 with background execution? Our app is registered with the audio background mode.
2
0
129
Jul ’25
Clarification of use of `AVAssetDownloadConfiguration` and `AVAssetDownloadTask` to persist MP3 Audio downloads/streams
Hello! I have been following the UsingAVFoundationToPlayAndPersistHTTPLiveStreams sample code in order to test persisting streams to disk. In addition to support for m3u8, I have noticed in testing that this also seems to work for MP3 Audio, simply by changing the plist entries to point to remote URLs with audio/mpeg content. Is this expected, or are there caveats that I should be aware of? Thanks you!
0
0
49
Apr ’25
Use of `for await` with `AyncStream`, and yielding async closures to its continuation
Hello, I was hoping to clarify my understanding of the use of for await with an AsyncStream. My use case is, I'd like to yield async closures to the stream's continuation, with the idea that, when I use for await with the stream to process and execute the closures, it would only continue on to the following closure once the current closure has been run to completion. At a high level, I am trying to implement in-order execution of async closures in the context of re-entrancy. An example of asynchronous work I want to execute is a network call that should write to a database: func syncWithRemote() async -> Void { let data = await fetchDataFromNetwork() await writeToLocalDatabase(data) } For the sake of example, I'll call the intended manager of closure submission SingleOperationRunner. where, at a use site such as this, my desired outcome is that call 1 of syncWithRemote() is always completed before call 2 of it: let singleOperationRunner = SingleOperationRunner(priority: nil) singleOperationRunner.run { syncWithRemote() } singleOperationRunner.run { syncWithRemote() } My sketch implementation looks like this: public final class SingleOperationRunner { private let continuation: AsyncStream<() async -> Void>.Continuation public init(priority: TaskPriority?) { let (stream, continuation) = AsyncStream.makeStream(of: (() async -> Void).self) self.continuation = continuation Task.detached(priority: priority) { // Will this loop only continue when the `await operation()` completes? for await operation in stream { await operation() } } } public func run(operation: @escaping () async -> Void) { continuation.yield(operation) } deinit { continuation.finish() } } The resources I've found are https://developer.apple.com/videos/play/wwdc2022-110351/?time=1445 and https://forums.swift.org/t/swift-async-func-to-run-sequentially/60939/2 but do not think I have fully put the pieces together, so would appreciate any help!
2
0
284
Mar ’25
Best approach for auto-play when using AVPlayer
Hello! I am trying to determine the best approach with AVPlayer for implementing auto-play, that is, playback that automatically starts without user initiation. Ideally this would work for both local and streaming audio. My current approach is using KVO and the status on an AVPlayerItem equal to readyToPlay to do this, but I was wondering if there was a better property or state to use, or, alternatively, whether this use case may already be handled when automaticallyWaitsToMinimizeStalling is true, so that I could simply write: player.replaceCurrentItem(with: AVPlayerItem(url: streamingUrl)) player.rate = 1 or let playerItem = AVPlayerItem(url: streamingUrl) player = AVPlayer(playerItem: playerItem) player.rate = 1 and expect the item to be auto-played when ready. In the context of user-initiated playback, I've typically seen code that makes a button's enabled state contingent on player.currentItem.duration, e.g. in AVFoundationSimplePlayer-iOS. On the other hand, AVAutoWait, which utilizes automaticallyWaitsToMinimizeStalling, does not seem to do this. As a side note, I am not using an AVQueuePlayer.
0
0
357
Mar ’25