BoringSSL Error

I'm quite new to Swift and have a problem that I can't solve since about 1,5 weeks. I was checking every forum if anyone has the same problem, but I couldn't find anyone. Would be cool if someone could help me. I want to get data from an website through parsing json.

My code to get the data looks like this:


func getData(){

let url = URL(string: "https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR")

let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in

if error != nil

{

print("ERROR")

} else

{

if let content = data

{

do

{

/

let myJson = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject

print(myJson)

let EthereumDataEUR = try JSONDecoder().decode([ethereumDataEUR].self, from: data!)

self.course = Double(EthereumDataEUR[0].price_eur)!

}

catch

{

}

}

}

}; task.resume()

label.text = String(format: "%.2f", course)

}



Every time I start the code in the simulator or real Device (it doesn't matter which one) I get the following code in the console:

2017-11-20 14:40:23.813604+0100 JsonTest[17534:5500248] [BoringSSL] Function boringssl_context_get_peer_sct_list: line 1757 received sct extension length is less than sct data length


I am using this code in viewWillAppear, so that the user has latest information when he starts the app or changes between tab bars. And I also use it in an extra function when he clicks on a button. I only get the boringSSl error when the data is downloaded the first time. I have got labels where the data that I download should be displayed, but it doesn't display after the first download. I hope you know what i mean? 🙂


Thanks for your help.

Answered by DTS Engineer in 280462022

On the second click on the button, I don't get the boringSSL error …

Right. That’s very likely the result of some sort of caching in the networking layer, for example:

This caching means that the networking stack does less work, which means it never runs the code that generates this log message.

If my theory is correct then this log message is completely unrelated to your ‘data not displaying’ problem. You can test that by adding some log statements to the first line of the closure you pass to

dataTask(with:)
.
print(data)
print(response)
print(error)

I suspect you’ll see that this closure is called with the correct data in both cases.

As to why the data isn’t showing up in your UI, I suspect that’s because you’re setting it from a secondary thread. Remember that:

  • dataTask(with:)
    calls its completion closure on some unspecified secondary thread
  • UIKit can only be called from the main thread

If you call UIKit from a secondary thread you will encounter all sorts of weird problems, including delays like the ones you’re currently seeing.

A good way to flush out issues like this is to enable Main Thread Checker in the Diagnostics tab of your Run scheme.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

First up, with regards the delay getting your question posted, that’s likely because most of Apple was shut down last week in observance of the US Thanksgiving holiday.

With regards Apple’s use of BoringSSL, this is an implementation detail that’s not really relevant to the developer story (other than for debugging issues like this one). You can find my advice with regards choosing a TLS implementation in this post.

With regards the specific log message you’re seeing, is there any indication that the log message is causing an actual problem? If not, my advice is that you ignore it. Lot of Apple frameworks generate lots of debugging output, and you can generally ignore it unless there’s a specific cause for concern.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your reply.

I will try to explain my problem with an example:

I have a button and when I click on the button, the data should be downloaded and the values of the data then should be displayed in labels.

I am also printing my downloaded data in the console.

So if I click on the button for the first time, I get the boringSSL error. Also the correct data is written in the console but it doesn't display in the labels.

On the second click on the button, I don't get the boringSSL error and the data is correctly displayed in the labels.

So the error only occurs on the first download.


And of course this isn't very user-friendly if you always have to click a button twice.

I currently got around this problem with a timer that clicks on the button again after 0.4s, but thats not very elegant of course. And additionally you see a delay in displaying the data because of my "solution" and thats not very nice in my opinion.


I hope I described my problem understandable and that you have a solution for me 🙂.

Accepted Answer

On the second click on the button, I don't get the boringSSL error …

Right. That’s very likely the result of some sort of caching in the networking layer, for example:

This caching means that the networking stack does less work, which means it never runs the code that generates this log message.

If my theory is correct then this log message is completely unrelated to your ‘data not displaying’ problem. You can test that by adding some log statements to the first line of the closure you pass to

dataTask(with:)
.
print(data)
print(response)
print(error)

I suspect you’ll see that this closure is called with the correct data in both cases.

As to why the data isn’t showing up in your UI, I suspect that’s because you’re setting it from a secondary thread. Remember that:

  • dataTask(with:)
    calls its completion closure on some unspecified secondary thread
  • UIKit can only be called from the main thread

If you call UIKit from a secondary thread you will encounter all sorts of weird problems, including delays like the ones you’re currently seeing.

A good way to flush out issues like this is to enable Main Thread Checker in the Diagnostics tab of your Run scheme.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your answer, and the good tip to enable the Main Thread Checker.


I have now found the reason why the label didn't update. The label got updated before the data was downloaded.

I fixed that by updating the label inside DispatchQueue.main.async{ } right after self.course = Double(EthereumDataEUR[0].price_eur)!

Thank you very much for you help. 🙂

BoringSSL Error
 
 
Q