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