This is an automated email from the ASF dual-hosted git repository.
curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 8f852e967 fix(csharp/src): handle HTTP authorization exception for
Thrift-based drivers (#3551)
8f852e967 is described below
commit 8f852e967aa2c990efa86528f29c017a127f72f5
Author: Bruce Irschick <[email protected]>
AuthorDate: Thu Oct 9 10:19:15 2025 -0700
fix(csharp/src): handle HTTP authorization exception for Thrift-based
drivers (#3551)
C# Thrift-based drivers using HTTP transport don't throw AdbcException
with AdbcStatusCode of Unauthorized.
As a best practice, drivers should indicate if the connection
encountered an authentication or authorization error when attempting to
open. Connection should throw an AdbcException with Status ==
AdbcStatusCode.Unauthorized.
This handles all Apache (Hive, Impala, Spark) and Databricks drivers
that use HTTP transport.
Notes:
* required an update to Thrift version 0.22.0 (then also
System.Text.Json 9.0.0)
closes #3550
---
csharp/src/Apache.Arrow.Adbc/AdbcException.cs | 1 +
.../src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj | 4 ++--
.../Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj | 4 ++--
.../Drivers/Apache/Hive2/HiveServer2Connection.cs | 21 +++++++++++++++++++++
.../Apache.Arrow.Adbc.Drivers.BigQuery.csproj | 2 +-
...che.Arrow.Adbc.Telemetry.Traces.Listeners.csproj | 4 ++--
.../Apache.Arrow.Adbc.Tests.csproj | 2 +-
csharp/test/Drivers/Apache/Hive2/DriverTests.cs | 3 +++
csharp/test/Drivers/Apache/Impala/DriverTests.cs | 3 +++
csharp/test/Drivers/Databricks/E2E/DriverTests.cs | 3 +++
10 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
b/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
index c4deada39..885262e4a 100644
--- a/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
+++ b/csharp/src/Apache.Arrow.Adbc/AdbcException.cs
@@ -44,6 +44,7 @@ namespace Apache.Arrow.Adbc
public AdbcException(string message, AdbcStatusCode statusCode,
Exception innerException)
: base(message, innerException)
{
+ _statusCode = statusCode;
}
public AdbcException(string message, Exception innerException)
diff --git a/csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
b/csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
index 005a5cd01..4f92168e1 100644
--- a/csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
+++ b/csharp/src/Apache.Arrow.Adbc/Apache.Arrow.Adbc.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
@@ -10,7 +10,7 @@
<PackageReference Include="System.Diagnostics.DiagnosticSource"
Version="9.0.6" />
</ItemGroup>
<ItemGroup
Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework),
'net6.0'))">
- <PackageReference Include="System.Text.Json" Version="8.0.5" />
+ <PackageReference Include="System.Text.Json" Version="9.0.9" />
</ItemGroup>
<ItemGroup
Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework),
'net6.0'))">
<Compile Remove="C\NativeLibrary.cs" />
diff --git a/csharp/src/Drivers/Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj
b/csharp/src/Drivers/Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj
index 8e68c63f3..d3679134c 100644
--- a/csharp/src/Drivers/Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj
+++ b/csharp/src/Drivers/Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj
@@ -5,11 +5,11 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="ApacheThrift" Version="0.21.0" />
+ <PackageReference Include="ApacheThrift" Version="0.22.0" />
</ItemGroup>
<ItemGroup
Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework),
'net6.0'))">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
- <PackageReference Include="System.Text.Json" Version="8.0.5" />
+ <PackageReference Include="System.Text.Json" Version="9.0.9" />
</ItemGroup>
<ItemGroup>
diff --git a/csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs
b/csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs
index 193cec722..fddb356f1 100644
--- a/csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs
+++ b/csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs
@@ -20,6 +20,8 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
+using System.Net;
+using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
@@ -356,6 +358,11 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
session = await Client.OpenSession(request,
cancellationToken);
}
+ catch (TTransportException transportEx)
+ when (ApacheUtility.ContainsException(transportEx, out
HttpRequestException? httpEx) && IsUnauthorized(httpEx!))
+ {
+ throw new HiveServer2Exception(transportEx.Message,
AdbcStatusCode.Unauthorized, transportEx);
+ }
catch (Exception)
{
if (FallbackProtocolVersions.Any())
@@ -381,6 +388,15 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
});
}
+ private static bool IsUnauthorized(HttpRequestException httpEx)
+ {
+#if NET5_0_OR_GREATER
+ return httpEx.StatusCode == HttpStatusCode.Unauthorized;
+#else
+ return httpEx.Message.IndexOf("unauthorized",
StringComparison.OrdinalIgnoreCase) >= 0 ||
httpEx.Message.IndexOf("authenticat", StringComparison.OrdinalIgnoreCase) >= 0;
+#endif
+ }
+
private async Task<TOpenSessionResp?>
TryOpenSessionWithFallbackAsync(TOpenSessionReq originalRequest,
CancellationToken cancellationToken)
{
Exception? lastException = null;
@@ -405,6 +421,11 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
throw new TimeoutException("The operation timed out while
attempting to open a session. Please try increasing connect timeout.", ex);
}
+ catch (TTransportException transportEx)
+ when (ApacheUtility.ContainsException(transportEx, out
HttpRequestException? httpEx) && IsUnauthorized(httpEx!))
+ {
+ throw new HiveServer2Exception(transportEx.Message,
AdbcStatusCode.Unauthorized, transportEx);
+ }
catch (Exception ex)
{
lastException = ex;
diff --git
a/csharp/src/Drivers/BigQuery/Apache.Arrow.Adbc.Drivers.BigQuery.csproj
b/csharp/src/Drivers/BigQuery/Apache.Arrow.Adbc.Drivers.BigQuery.csproj
index 16316d301..b65ab720e 100644
--- a/csharp/src/Drivers/BigQuery/Apache.Arrow.Adbc.Drivers.BigQuery.csproj
+++ b/csharp/src/Drivers/BigQuery/Apache.Arrow.Adbc.Drivers.BigQuery.csproj
@@ -9,7 +9,7 @@
<PackageReference Include="Google.Cloud.BigQuery.V2" Version="3.11.0" />
</ItemGroup>
<ItemGroup
Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework),
'net6.0'))">
- <PackageReference Include="System.Text.Json" Version="8.0.5" />
+ <PackageReference Include="System.Text.Json" Version="9.0.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference
Include="..\..\Apache.Arrow.Adbc\Apache.Arrow.Adbc.csproj" />
diff --git
a/csharp/src/Telemetry/Traces/Listeners/Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj
b/csharp/src/Telemetry/Traces/Listeners/Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj
index a688ba3fa..329a534d6 100644
---
a/csharp/src/Telemetry/Traces/Listeners/Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj
+++
b/csharp/src/Telemetry/Traces/Listeners/Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
@@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource"
Version="9.0.6" />
- <PackageReference Include="System.Text.Json" Version="8.0.5" />
+ <PackageReference Include="System.Text.Json" Version="9.0.9" />
<PackageReference Include="System.Threading.Channels" Version="9.0.8" />
</ItemGroup>
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
b/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
index 2884c49d8..20a4bb948 100644
--- a/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
@@ -13,7 +13,7 @@
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="OpenTelemetry" Version="1.12.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource"
Version="9.0.6" />
- <PackageReference Include="System.Text.Json" Version="8.0.5" />
+ <PackageReference Include="System.Text.Json" Version="9.0.9" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
diff --git a/csharp/test/Drivers/Apache/Hive2/DriverTests.cs
b/csharp/test/Drivers/Apache/Hive2/DriverTests.cs
index df915c0ca..f86bff6b1 100644
--- a/csharp/test/Drivers/Apache/Hive2/DriverTests.cs
+++ b/csharp/test/Drivers/Apache/Hive2/DriverTests.cs
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
+using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
using Xunit;
using Xunit.Abstractions;
@@ -96,6 +97,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Apache.Hive2
AdbcDatabase database = driver.Open(parameters);
AggregateException exception =
Assert.ThrowsAny<AggregateException>(() => database.Connect(parameters));
+ Assert.True(ApacheUtility.ContainsException(exception, out
AdbcException? adbcException), $"Expect AdbcException. Actual type:
{exception.GetType().Name}");
+ Assert.Equal(AdbcStatusCode.Unauthorized, adbcException!.Status);
OutputHelper?.WriteLine(exception.Message);
}
diff --git a/csharp/test/Drivers/Apache/Impala/DriverTests.cs
b/csharp/test/Drivers/Apache/Impala/DriverTests.cs
index a3a7e61c1..1f459a224 100644
--- a/csharp/test/Drivers/Apache/Impala/DriverTests.cs
+++ b/csharp/test/Drivers/Apache/Impala/DriverTests.cs
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
+using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Impala;
using Apache.Arrow.Adbc.Tests.Metadata;
using Xunit;
@@ -75,6 +76,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Apache.Impala
AdbcDatabase database = driver.Open(parameters);
AggregateException exception =
Assert.ThrowsAny<AggregateException>(() => database.Connect(parameters));
+ Assert.True(ApacheUtility.ContainsException(exception, out
AdbcException? adbcException), $"Expect AdbcException. Actual type:
{exception.GetType().Name}");
+ Assert.Equal(AdbcStatusCode.Unauthorized, adbcException!.Status);
OutputHelper?.WriteLine(exception.Message);
}
diff --git a/csharp/test/Drivers/Databricks/E2E/DriverTests.cs
b/csharp/test/Drivers/Databricks/E2E/DriverTests.cs
index e072ca2a8..26402aebc 100644
--- a/csharp/test/Drivers/Databricks/E2E/DriverTests.cs
+++ b/csharp/test/Drivers/Databricks/E2E/DriverTests.cs
@@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Spark;
using Apache.Arrow.Adbc.Tests.Drivers.Apache.Common;
using Xunit;
@@ -130,6 +131,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Databricks
AdbcDatabase database = driver.Open(parameters);
AggregateException exception =
Assert.ThrowsAny<AggregateException>(() => database.Connect(parameters));
+ Assert.True(ApacheUtility.ContainsException(exception, out
AdbcException? adbcException), $"Expect AdbcException. Actual type:
{exception.GetType().Name}");
+ Assert.Equal(AdbcStatusCode.Unauthorized, adbcException!.Status);
OutputHelper?.WriteLine(exception.Message);
}