46

I am getting some SSL Errors (which are causing my project to stop/hang with no crash as I have a DispatchGroup waiting for the request), which I don't know how they are caused, what they are, or what to do about it.

I have read numerous pages roughly about this problem, but there are not much documentation or people having the same problem. I have tried changing the info.plist but that doesn't seem to have helped. Both plist's look like this: (accounts.spotify.com is the domain for the URL of the access token request)

enter image description here

I can see that my code is failing when I make a request to the server. (This is in my framework). As mentioned earlier, I have a DispatchGroup waiting for this request but the code stops.

self.currentToken = try self.spotifyRequest("https://accounts.spotify.com/api/token", method: .post, parameters: parameters)

My request method:

private func spotifyRequest(_ url: URLConvertible, method: HTTPMethod, parameters: Parameters? = nil, headers: HTTPHeaders? = nil) throws -> JSONStandard {
    // Create a dispatch group to handle threads
    let group = DispatchGroup()
    group.enter()

    // Status of the request (starts as nil)
    var status: JSONStandard?


    DispatchQueue.global(qos: .userInitiated).async {
        Alamofire.request(url, method: method, parameters: parameters, headers: headers).responseJSON(completionHandler: { response in
            // Check if response is valid
            if let requestResponse = response.result.value as? JSONStandard {
                status = requestResponse
            } else {
                status = nil
            }

            // Let the next tasks be completed, it has finished waiting for the request
            group.leave()
        })
    }


    // Wait for a result
    group.wait()

    // Return value or throw an error
    if let safeStatus = status {
        return safeStatus
    } else {
        getAccessToken()
        throw SpotifyError.failedToCompleteRequest
    }
}

I'm not exactly sure what caused the problem, because all I did was slightly edit and archive the framework again.

However, earlier it worked on both (as I am using this universal framework script)

Here is my crash log (which I can't understand any of!):

2018-08-18 21:36:45.747984+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.748123+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.748238+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.748432+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.754554+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.754640+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:36:45.754717+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_errorlog(224) [C2.1:2][0x107d7c600] [boringssl_session_read] SSL_ERROR_SSL(1): operation failed within the library

2018-08-18 21:36:45.754796+0100 Songvote[4854:1517160] [BoringSSL] boringssl_session_handshake_error_print(205) [C2.1:2][0x107d7c600] 4427428040:error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl/boringssl-109.200.32/ssl/ssl_lib.cc:1081:

2018-08-18 21:38:43.427156+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1b4c0] get output frames failed, state 8196

2018-08-18 21:38:43.427656+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1b4c0] get output frames failed, state 8196

2018-08-18 21:38:43.429723+0100 Songvote[4854:1517503] TIC Read Status [1:0x0]: 1:57

2018-08-18 21:38:43.429976+0100 Songvote[4854:1517503] TIC Read Status [1:0x0]: 1:57

2018-08-18 21:38:46.008365+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x107d7c600] get output frames failed, state 8196

2018-08-18 21:38:46.008664+0100 Songvote[4854:1517503] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x107d7c600] get output frames failed, state 8196

2018-08-18 21:38:46.010037+0100 Songvote[4854:1517503] TIC Read Status [2:0x0]: 1:57

2018-08-18 21:38:46.010215+0100 Songvote[4854:1517503] TIC Read Status [2:0x0]: 1:57

enter image description here

This is all for a Spotify request through Alamofire which previously worked and now mysteriously doesn't. It does not work on my device OR the simulator.

Is this a problem relating to secure internet connections? Or is this another problem?

Some links to what I have looked at:

Edits:

Is this a problem on Spotify's servers? Or a bug in Xcode 10? I moved my framework .swift files to my project, and still get the logs.

I also get these errors before my request, strange .

This is what a handshake error is, but I don't do any configuring of this:

The SSL handshake is initiated when your browser issues a secure connection request to a Web server. The server sends a public key to your computer, and your computer checks the certificate against a known list of certificate authorities. ... Test your SSL functionality by intentionally causing the handshake to fail.

I even tried checkout on an earlier version to reverse all changes (which definitely worked completely fine in earlier versions) using git, which had no affect on this.


Edit: The temporary solution:

It appears as though iOS 12 no longer works with these network requests. I sent a bug report to Apple 2 days ago, so hopefully they will fix this soon. So what did I do?

Well, for now, my iPhone 7 is useless as I am on iOS 12 beta. So the only option for now is to run my project on the simulator. To do this (as if you are in Xcode 10 beta because the simulators are iOS 12), go to Xcode -> Preferences -> Components -> iOS 11.4 Simulator and then download it. Now, when you select a simulator, select the ones that say iOS 11.4.

  • This part is no longer true.

What causes this?

Although this error should not effect anything, it is caused when you run your project in iOS 12. As far as I know, this is NOT a security issue. However, my problem of my code not running was caused by a deadlock instead of what I thought to be was because of this error.

Update: What Apple has done about my bug report

Well, although I didn't receive a message or anything from Apple, the report is marked as a 'duplicate' as someone else had reported this before me. If I get any information about when it will be fixed, I will update it here.


If you have any questions, tips or pointers, please let me know! Thanks in advance!

George_E
  • 8,913
  • 3
  • 35
  • 76
  • 1
    I am experiencing the same issue. My application worked fine with iOS <= 11 and Xcode 9. After reports of crashing in iOS 12, I decided to get Xcode 10 and try running the app in a device simulator with iOS 12 and this is exactly what's happening. The application fails to make any requests to the server using HTTPS. – Tarps Aug 21 '18 at 11:10
  • 1
    @Travo Glad it's not just me! I am also connecting to `https`, so `AppTransportSecurity` settings probably won't make a difference as it should be a very secure network (considering I am connecting to two massive companies, `Spotify` and `Google's Firebase`). – George_E Aug 21 '18 at 11:13
  • @Travo It's also frustrating that Apple doesn't support an easy way of Swift backward-compatibly otherwise I would create my whole project in Xcode 9 for now instead. However, most lines of code need to be changed because everything keeps getting deprecated. I do not want to spend lots of time remaking my project for an older version of Xcode, until I know for almost certain that the problem *is* Xcode itself rather that what my requests connect to. – George_E Aug 21 '18 at 11:18
  • 1
    I feel you. New Swift versions, twice a year. I, aswell, found a lot of issue reports regarding SSL failures in iOS 12 beta 2. I would love to imagine that the issue at hand is limited to the iOS 12 beta 7 that is currently live. I am literally out of ideas on how to fix this. It seems like an OS failure we are unable to control. – Tarps Aug 21 '18 at 11:20
  • @Travo If you can, we should start a chatroom for these comments, as there is going to be a lot – George_E Aug 21 '18 at 11:24
  • @Travo I submitted a bug report about this 2 days ago, but knowing Apple, they will probably come back in a week and say "we cannot recreate your problem, please provide more information" like how they always ignore serious bugs. – George_E Aug 21 '18 at 11:26
  • Ran some more quick tests. Application works fine in iOS 11.4.1 (iPhone 8 real device, iPhone X simulator), even when built with Xcode 10. iOS 12 is the sole cause of the problem here. – Tarps Aug 21 '18 at 12:09
  • @Travo Right, that's interesting, for me I can't even build my project with my frameworks, (a separate problem), but my project doesn't work on my device as I have iOS 12 beta – George_E Aug 21 '18 at 12:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/178449/discussion-between-george-e-2-and-travo). – George_E Aug 21 '18 at 13:00
  • @Travo Check the discussion chat – George_E Aug 21 '18 at 13:40
  • I also have strange network problems with iOS 12 beta with some (not every) test iPhones. In iOS 12 simulator with Xcode 10 beta6 the network request was working fine in our app. However on a physical iPhone 7 device (running iOS 12 beta12) the network request failed - no response. Using an iOS 11 test iPhone device with the very same app, same request it worked, too. Also it works in iOS 11 Simulator. Turned out I had to do a full erease on our iOS 12 beta12 test iPhone. After the full erase I ran the very same app in Xcode 10 onto the freshly installed iPhone and it worked. – balazs630 Sep 12 '18 at 13:36
  • @balazs630 So was your iOS 12 corrupt then? That was a strange problem... – George_E Sep 12 '18 at 14:43
  • Not corrupt but some kind of stucked outdated certificate maybe (?) This explains a lot: https://stackoverflow.com/a/38235622/7343596 – balazs630 Sep 12 '18 at 14:49
  • Has Apple gone back to you on this issue @George_E_2 or have you found a more sustainable solution? I'm having the same problem with the native URLSession.shared.dataTask. What's weird is that I can make one first call which executes normally, but if I hit the button again (triggering a new API call), that's where the deadlock occurs and the completionHandler never gets called. (I'm using Google's YouTube data API (v3) FWIW). – Edouard Barbier Sep 25 '18 at 12:36
  • @EdouardBarbier They never got back to me by a message, however they have marked my report as a duplicate so they are aware of the issue. Hopefully they sort the problem out soon. Also, the deadlock in my code was caused by the threads locking. This 'warning' should not effect anything, including you `URLSession`. You must have a logic problem in the code like I originally did. – George_E Sep 25 '18 at 16:34
  • @George_E_2 thanks for getting back to me. I indeed had something weird happening with my activity indicator which was beginning to ignore touch events but not stopping to ignore them later on. The app looked frozen and I was investigating in the wrong direction. Thanks for the update on the warning, I hope it gets fixed soon too ;) – Edouard Barbier Sep 26 '18 at 16:12
  • 2
    I'm having this EXACT same issue. Our app was working completely fine up until iOS 12 a few days ago, and now we're getting a string of errors, and its causing our app to completely deadlock. Did you fix this? See my latest post. Dying for a solution: https://stackoverflow.com/questions/52565371/obj-c-tic-read-status-in-xcode-console – Brittany Oct 01 '18 at 00:49
  • @Brittany Quite a lot of people are having this issue. See the bottom of my question under the **bold** titles, but to briefly put it, the warning shouldn't effect your code. For me, I got a deadlock due to bad thread management. – George_E Oct 01 '18 at 18:03
  • 1
    Wow @George_E_2...you're totally right. As soon as I move my attempt to connect to the database out of AppDelegate, I'm able to connect as normal again, sans errors in the console. Any idea why this is/why iOS 12 changed this? – Brittany Oct 01 '18 at 21:24
  • @Brittany No idea. It must be a bug, and I suspect iPhones (and iPads) have one less layer of internet security protection. Time will tell what that security flaw is, or Apple will just secretly patch it up. – George_E Oct 02 '18 at 18:46

2 Answers2

16

Deadlock

I assume spotifyRequest will be called on the main thread.

So if the main thread reaches the line

group.wait()

and this line of responseJSON completionHandler was not called yet:

group.leave()

then the main thread is blocked due to the call of group.wait() above. Due to the blocked main thread group.leave() can't be called. Classical deadlock.

Verfication

Setting a breakpoint to the line

if let safeStatus = status {

shows that this line is never called.

Minimal Example that is running

As a starting point here the code for a minimal example that delivers a result.

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.contactSpotify {
            print ("result: \(String(describing: $0)) error: \(String(describing: $1))")
        }
    }

    func contactSpotify(completion: @escaping ([String: Any]?, Error?) -> Void) {
        let url = URL(string: "https://accounts.spotify.com/api/token")!
        Alamofire.request(url,
                          method: .post,
                          parameters: ["grant_type": "refresh_token",
                                       "client_id": "<someClientId>",
                                       "refresh_token": "<someRefreshToken>",
                                       "client_secret": "<someClientSecret>"])
            .validate()
            .responseJSON { response in
                guard response.result.isSuccess else {
                    completion(nil, response.result.error)
                    return
                }

                completion(response.result.value as? [String: Any], nil)
        }
    }

}

This gives as output in the console:

result: Optional(["access_token": XXX, "scope": user-read-email user-read-private, "token_type": Bearer, "expires_in": 3600]) error: nil

see Screenshot: console output

ATS Settings in info.plist

Spotify offers a valid TLS certificate chain on their server. So there is no need for ATS settings in info.plist.

SSL Warnings in Console

I get the same SSL warnings in the console when I run the application on an iOS 12 simulator like you. Nonetheless the connection is established and the request delivers data. Perhaps this is gone in one of the next betas.

Stephan Schlecht
  • 18,637
  • 1
  • 22
  • 33
  • I realised that I had a deadlock after that... I'm fixing them right now actually. But this is the correct answer, the warnings were just due to iOS 12 – George_E Aug 21 '18 at 20:15
  • 2
    That's also a nicely detailed answer as well :) – George_E Aug 21 '18 at 20:16
  • I know it's been a while, but just out of curiosity, why choosing dispatch groups over Promises? (like BFTasks, or observables like RxSwift) What was the deciding factor? – Alex Nov 21 '18 at 10:40
  • @Alex I have abandoned this app now... Anyway, I was very new to Alamofire and inexperienced. I still am as I don't use it any more. But I have no idea what Promises were, so this was my solution at the time. The real issue was returning a value synchronously on an asynchronous thread, but I did that as I was trying to make a framework for future projects. – George_E Nov 25 '18 at 17:51
0

I had the same warning with codegen Swagger in emulator on any response call. But all worked. This warning disappeared only when I added environment variable Hide strange unwanted Xcode logs

Zhebzhik Babich
  • 901
  • 8
  • 21