SSL Connection Issues After Upgrading to Unity 6, Resolved by Downgrading to 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.

22 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.

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.

1 Like

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.

2 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.