Hey @Topias_Nykanen & @scott, I’m running into the same problem, and will try to provide more information.
influxdb3 3.0.1, revision d7c071e0c4959beebc7a1a433daf8916abd51214
(installed on local Windows 11 machine)
Unity Editor version 2022.3.61f1
.Net Framework (instead of .Net Standard. Tried both, equivalent behavior.)
InfluxDB3.Client version 1.1.0 (installed through NuGet For Unity)
My code, from an async void MonoBehaviour.Start() function:
const string host = "https://localhost:8181";
const string token = "apiv3_myadminkeyblabla";
const string database = "my_database";
using var client = new InfluxDBClient(host, token: token, database: database);
...
var point = PointData.Measurement("kline");
...
point.SetTag("symbol", testSymbol);
point.SetDoubleField("volume", double.Parse(parts[5]));
point.SetTimestamp(long.Parse(parts[6]), WritePrecision.Us);
...
await client.WritePointAsync(point); // Exception thrown here
The specific exception shows a TLS handshake failure:
TlsException: Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: UNITYTLS_X509VERIFY_NOT_DONE
Mono.Unity.Debug.CheckAndThrow (Mono.Unity.UnityTls+unitytls_errorstate errorState, Mono.Unity.UnityTls+unitytls_x509verify_result verifyResult, System.String context, Mono.Security.Interface.AlertDescription defaultAlert) (at <17c1853552e149c38adf7a327ade40e6>:0)
Mono.Unity.UnityTlsContext.ProcessHandshake () (at <17c1853552e149c38adf7a327ade40e6>:0)
Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus status, System.Boolean renegotiate) (at <17c1853552e149c38adf7a327ade40e6>:0)
(wrapper remoting-invoke-with-check) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus,bool)
Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus status) (at <17c1853552e149c38adf7a327ade40e6>:0)
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
Rethrow as AuthenticationException: Authentication failed, see inner exception.
Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication (System.Boolean runSynchronously, Mono.Net.Security.MonoSslAuthenticationOptions options, System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
Mono.Net.Security.MonoTlsStream.CreateStream (System.Net.WebConnectionTunnel tunnel, System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.WebConnection.CreateStream (System.Net.WebOperation operation, System.Boolean reused, System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
Rethrow as WebException: Error: SecureChannelFailure (Authentication failed, see inner exception.)
System.Net.WebConnection.CreateStream (System.Net.WebOperation operation, System.Boolean reused, System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.WebOperation.Run () (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.WebCompletionSource`1[T].WaitForCompletion () (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.HttpWebRequest.RunWithTimeoutWorker[T] (System.Threading.Tasks.Task`1[TResult] workerTask, System.Int32 timeout, System.Action abort, System.Func`1[TResult] aborted, System.Threading.CancellationTokenSource cts) (at <17c1853552e149c38adf7a327ade40e6>:0)
System.Net.Http.MonoWebRequestHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) (at <45470e4a4fae4e658de164eff058675f>:0)
Rethrow as HttpRequestException: An error occurred while sending the request
System.Net.Http.MonoWebRequestHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) (at <45470e4a4fae4e658de164eff058675f>:0)
System.Net.Http.HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) (at <45470e4a4fae4e658de164eff058675f>:0)
InfluxDB3.Client.Internal.RestClient.Request (System.String path, System.Net.Http.HttpMethod method, System.Net.Http.HttpContent content, System.Collections.Generic.Dictionary`2[TKey,TValue] queryParams, System.Collections.Generic.Dictionary`2[TKey,TValue] headers, System.Threading.CancellationToken cancellationToken) (at <16fc6e3eb88a4c35a4252b398f053269>:0)
InfluxDB3.Client.InfluxDBClient.WriteData (System.Collections.Generic.IEnumerable`1[T] data, System.String database, System.Nullable`1[T] precision, System.Collections.Generic.Dictionary`2[TKey,TValue] headers, System.Threading.CancellationToken cancellationToken) (at <16fc6e3eb88a4c35a4252b398f053269>:0)
Note that I’ve tried:
using var client = new InfluxDBClient(host, token: token, database: database, authScheme: "Bearer");
because when I created the admin access token, the console gave this message:
HTTP requests require the following header: "Authorization: Bearer apiv3_myadminkeyblabla"
This will grant you access to HTTP/GRPC API
while I see that in InfluxDbClient.cs the httpClient is created with “Token” as the authScheme by default:
string scheme = (string.IsNullOrEmpty(config.AuthScheme) ? "Token" : config.AuthScheme);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(scheme, config.Token);
but I’m not sure that this matters. It yields the same error.
More importantly I’ve tried using a garbage token:
using var client = new InfluxDBClient(host, token: "incorrectToken", database: database);
which gives exactly the same error. That leads me to believe the handshake doesn’t get to the point of actually checking the token?
I saw there has been a bug related to this TLS error in slightly older Unity versions, but I get the same problem after upgrading to one beyond the versions containing the fix.