SSL Connection Issues After Upgrading to Unity 6, not present in Unity 2021.3.30

Since upgrading to Unity 6, we’ve been facing a recurring issue in our project related to network connections, specifically SSL failures (Curl error 35 and Curl error 6). These errors occur after long play sessions and affect our game’s connection to external services, both in the editor and in builds. Notably, even after stopping and restarting the game in the editor, we cannot reconnect to external services unless we restart the entire editor.

We’ve done extensive troubleshooting, including profiling, monitoring network traffic, and reviewing our network handling code, but we haven’t been able to pinpoint the exact cause. One significant observation is that the issue starts with the error Exception: Unable to complete SSL connection. Additionally, when the issue occurs, Wireshark shows no network activity from Unity, indicating that network calls aren’t even reaching the network interface at that point.

We’ve tried using the latest Unity 6 version (6000.18), but the issue persists. However, when we downgraded to Unity 2021.3.30, the problem no longer occurs.

For more context:

  • Our game makes regular network calls to external services.
  • Sentry logs frequently show the error: System.Exception: Cannot resolve destination host.
  • In Sentry, after some time, we also see a failure in sending data to its server with the error Mono.Security.Interface.TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR. And in editor I get TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: UNITYTLS_X509VERIFY_NOT_DONE
  • We’ve tried updating the client certificate (X509Certificate2Collection), but this hasn’t resolved the issue.

The strangest part is that everything works fine initially, but after some time (which varies between 40 minutes to over 3 hours), the issue suddenly appears. We suspect there may be a leak or some issue related to SSL handshakes, but we’re not sure how to capture or prove this behavior.

Has anyone else experienced similar issues with Unity 6, or could anyone offer advice on how to further investigate or resolve this problem?

------------------------------------------Edit: New Findings--------------------------------------

  • Trigger Mechanism:
    The issue appears to be triggered by a high number of concurrent web requests, particularly in Unity’s internal web request handling system. We suspect that Unity is not properly freeing up network sockets after requests, leading to socket exhaustion over time.

  • Pattern Observed:
    The problem occurs more quickly when a higher number of concurrent web requests are made. For example:

    • With no concurrency limits, the issue arises after 2700-4000 requests.
    • Limiting concurrency to 20 requests delays the problem to around 8000-9000 requests.
    • Reducing to 15 concurrent requests extends this to approximately 12,500 requests.
      These numbers are approximate, but they illustrate a clear pattern: the more requests at once, the faster the issue occurs.
  • Network Traffic Monitoring:
    Once the issue starts, the first signs are SSL failures (Curl error 35). While some requests still succeed, eventually all requests fail with the error “Cannot resolve destination host.” Wireshark shows that no network traffic reaches the interface when the problem occurs, indicating that Unity is no longer making outbound requests.

  • Testing with HttpClient:
    We switched from Unity’s UnityWebRequest to C#'s HttpClient to handle network requests. By throttling the number of concurrent requests based on available sockets, we’ve been able to somehow avoid socket exhaustion.

  • Unity Version Differences:
    This issue is significantly less prominent in older versions of Unity (2021.3.30). While some queries fail in the older version, the connection doesn’t fully break, and additional requests can still be sent after clearing the queue.

23 Likes

I seem to have same behavior on unity 6 versions. I’ve tried several minor versions at random, but all seem to have same issues .2 .7 .16 .18

Wonder if this is related to the runtime fee code changes, which now want to send additional data without dev knowledge or control.

1 Like

We see the same thing, but haven’t used 2021.x for ages, and I’m pretty sure we could trigger it there, although as you say it seemed more difficult. In our case, it happens when opening large numbers of connections to S3 or Azure Storage buckets. We’ve been using a queue outside of UWR since forever, because ever since Unity 5 we’ve never trusted UWR to stay upright if you push it.

Are you on iOS? If so, I think quite a lot changed between 2021.x and 6000.x in terms of how unitywebrequest maps to NSUrlSession, which might explain some differences. Specifically, we see far less benefit (in terms of download throughput) to issuing numbers of UWRs concurrently on iOS on more recent Unitys.

I have the same issue, but with Unity 2022.3.
I have an idle game which people usually keep open for days and it was never an issue with Unity 2020. A few weeks ago I upgraded to Unity 2022.3.44f1 and since then there are issues with server connections after the game is kept open for 1-2 days and it only works again if the game is restarted. That causes a bit of an issue for the players.

It always starts with:

  • “Curl error 35: Handshake failed. UnityTls error code: 7” a few times,
  • then "Curl error 35: Cert verify failed. Certificate could not be verified (either omitted or unsupported). "
  • then “UnityTls error code: 7 a few times, then Curl error 6: getaddrinfo() thread failed to start” until around 100 times then it says error limit reached
  • after that “Cannot resolve destination host” until the game is restarted.

What I noticed is that if I keep the game and Unity editor running at the same time, the issue which is in the game also keeps happening in the editor until I restart the game.

I guess I could also try to downgrade to Unity 2021, but that is not really a long-term solution.

1 Like

I’ve looked into the issue and this seems to have been caused by this MbedTLS update:


This change is present in Unity 6000 and 2022.3.24+

I’ve debugged the issue and reported it to MbedTLS, Unity developers will need to update it again once the problem is fixed.

For everyone affected, please upvote the issue on GitHub to show the maintainers of the library that there are multiple users impacted by this.

3 Likes

This is an urgent issue blocking our next release, which is an update to Unity 2022. It’s also not great for our confidence in Unity 2022 and Unity 6. There was a previous SSL issue with concurrent UnityWebRequests that kept us from updating to 2022 for a while.

We didn’t (and still don’t) have any of these problems on Unity 2019.

Please let me know if I can provide any additional detail that’s not already here. We intend to reproduce the issue in an empty project tomorrow morning.

3 Likes

This is also affecting us since updating from 2022.3.37f to Unity 6000.0.19f1.

As mentioned before, the client stops sending web requests


--- Unity WebRequest ---
Code: 0
IsDone: True
UnityWebRequest.Result: ConnectionError
Error: Cannot resolve destination host
Timeout: 0
URI: https://[Removed]/app.php
URL: https://[Removed]/app.php
Downloaded bytes: 0
Downloaded progress: 1

The only “solution” is to restart the client/Unity editor. The only workaround I can think of at this moment is to force quit the app, when we detect this, so players can re-log in the game, that’s a really bad approach.

I can deal with connection loss and errors, but If anyone can think of a way to reset this without restarting the client that would be much appreciated.

I am seeing the same thing here after updating to 2022.3.49. It happens about 5 - 15 minutes in with large amounts of web requests. I found this bug report which seems to be the same issue. Please Unity fix this as its really effecting customers in our latest builds. Also upvote the issue so it gets prioritized! Unity Issue Tracker - "Unable to complete SSL connection" exceptions are thrown and connection fails when a large amount of WebRequests are made

Just chiming in to say we’re running into the same issue since upgrading to Unity 2021.3.40+. I have to restart the Untiy Editor frequently to get around the issue.

I just saw the issue got marked as by design by Unity. What the? This is unacceptable. There are many cases where lots of data is being streamed into Unity. In our case we are using Cesium for Unity which streams lots of terrain data through Google and Bing. This bug makes our product almost unusable as streaming data crashes every time the game is run. Unity please fix this issue as its a major road blocker. Unity Issue Tracker - "Unable to complete SSL connection" exceptions are thrown and connection fails when a large amount of WebRequests are made

2 Likes

Did you read the resolution notes as well?

Resolution Note:

At this moment UnityWebRequest does not impose any limitations on number of network connections. The attached project tries 1000 of them, which is way too many, web browsers typically limit connections to low two digit figures.
After I’ve limited per-host connection limit to 8, no issues were observed.

If your issue occurs with a limited amount of per host connections, you will need to file a bug with a repro project as you are clearly experiencing a different bug.

(Note: I’m just passing by because this thread was tagged with profiling tags. I have no particular insights into this.)

Yes, I read the resolution notes. That’s the problem, Cesium for Unity (which is a popular product with hundreds of clients) usually sends 30 or more connections at a time. And can add up to hundreds at a time. Where he gets the connection limit to only 8 is unacceptable. This was not the case in previous versions of Unity… Many applications are downloading data from more then 8 url’s at a time. And should support way more.

Why file another bug, if the bug posted reproduces the exact issue we are seeing?

Reasons why this is definitely still an issue:

  • Host limit reduces reproduction time exponentially, so setting a max of 8 will indeed no reproduce it unless you let it run for a few hours. Then you will still get the issue. We use a blockchain game with web requests, limitting to 20 concurrent requests, but it still triggers after 1/2 hours.
  • The issue did not happen on older unity versions
  • The issue is not just about not supporting many requests, its about the entire request service breaking and not allowing any new connections after triggering the issue, forcing the user to fully restart the game/editor.
  • It even triggers in the editor if using web requests for other stuff like analytics (yes including unity analytics), but it might take multiple hours, we generally experience it once per day (8 hours), even after rewriting our entire blockchain interaction to use HttpClient rather than Webrequests (as that one does work)
  • The resolution mentions the browser, but suprisingly, the issue does not uccor when running in the browser using webGPU. It occurs in the editor and standalone PC builds.

My guess is that something in the internal unity webrequests handling is not cleaned correctly and you slowly use up sockets until there are non left for the application, then any new ones fail as all slots are taking by broken connections.

Excuse my directness, but I am sad and suprised to see the issue closed as “By design” for such an incredibly impacting issue. We had to rewrite to use HttpClient to somewhat prevent the issue, otherwise our players wouldn’t be able to play for longer than ~1 hour. And again, this was only after upgrading unity. How can this be by design?

1 Like

I’m happy for the directness and pointing out that it only delays the issue. I’ve raised this internally to be revisited.

4 Likes

Thanks Martin,
Hopefully they can reopen the bug here and find a fix soon. So our users don’t have to restart our game every 15 min because of the connection errors.

There is another bug about this that remains open and is more precise in hitting the issue you are describing here, UUM-83744.

That bug report does seem similar, or at least matches with what I’ve been able to reproduce, hopefully it aids in getting it resolved since a lot of people are having issues as a result of the bug.

1 Like

It’s a related bug. This message pops up in the editor once Web Requests fail to function. I commented and pointed to the other bug so Unity is aware it’s the same issue.

Ah yeah, I already added an internal comment but a link to it from a public comment doesn’t hurt :slight_smile:

I posted this in the Unity Issue Tracker as well (link at the bottom)

Anybody still having network issues with Unity 6 on iOS?
I encountered the above SSL issues after upgrading to 6 from 2021.3.40 back in sep/oct (before 6000.0.25). I downgraded back to 2021 and they went away. After seeing that this issue has been fixed, yesterday I tried 6000.0.32 and ran into networking issues again. During two different extended test runs, deep into each test, there was a socket connection error on the iOS build. The Windows build ran all the way through the tests without error.

I downgraded again to 2021 and now the Windows and iOS builds run all the way through the tests without failures.

So I’m now wondering if the network problem was fully fixed. Perhaps it was two different errors and only one was fixed, or there was one error and it is only partially fixed.

Has anybody else encountered network errors that only surface after extensive runs?

Link to Unity Issue Tracker item: