Deadlock with NSOutputStream and URLSessionUploadTask (__psynch_mutexwait)

130 Views Asked by At

Our OSX app is uploading multiple files to the server using

func uploadTask(withStreamedRequest request: URLRequest) -> URLSessionUploadTask

While uploading, the upload gets stuck. Some files manage to upload successfully, sometimes more files other times less.

Looking at the debug navigator I can see that my stream thread shows two calls (one after the other; frame 11 and frame 5) to stream:handleEvent delegate, that points me to the code line where i call write:maxLength on NSOutputStrem, following __psynch_mutexwait in frame 0. At this point app is stuck and no network calls can finish executing.

enter image description here
Did anyone come across this issue? Any help is appreciated, thanks.

1

There are 1 best solutions below

1
Konrad Piascik On

It looks like your handler is being signaled twice to write to the same stream. Add a check that the streamStatus is NSStreamStatusWriting and return early.