Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net6-android: Environment.SetEnvironmentVariable not shared with native library #71153

Closed
Falco20019 opened this issue Jun 22, 2022 · 6 comments

Comments

@Falco20019
Copy link

Description

I just ported a Android library from MonoAndroid to net6-android. Sadly, the library (Grpc.Core.Xamarin) uses environment variables to pass the xds_bootstrap.json path over. There is no other way to set it.

On MonoAndroid, calling Environment.SetEnvironmentVariable("GRPC_XDS_BOOTSTRAP", "...") did work. On net6-android, I get a runtime error from the library:

[DOTNET] [16:39:29 ERR MainFrame] 3149119968 /var/local/git/grpc/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc:707: Failed to create xds client -- channel will remain in TRANSIENT_FAILURE: {"created":"@1655915969.698845100","description":"Environment variables GRPC_XDS_BOOTSTRAP or GRPC_XDS_BOOTSTRAP_CONFIG not defined","file":"/var/local/git/grpc/src/core/ext/xds/xds_client.cc","file_line":2359}

Reproduction Steps

  1. Create Android application using <TargetFramework>net6.0-android</TargetFramework>
  2. Add Grpc.Core.Xamarin using the following lines:
  <!-- Workaround for Grpc.Core.Xamarin -->
  <PropertyGroup>
    <Grpc_SkipNativeLibsCopy>true</Grpc_SkipNativeLibsCopy>
  </PropertyGroup>
  <ItemGroup>
    <!-- Use $(GrpcVersion) once packages are available! -->
    <PackageReference Include="Grpc.Core.Xamarin" Version="2.44.0" GeneratePathProperty="true" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\arm64-v8a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\armeabi-v7a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\x86\libgrpc_csharp_ext.so" />
  </ItemGroup>
  1. Try to call any endpoint with a target that uses xds:///

Expected behavior

The call should be made using xDS name resolution.

Actual behavior

The call failed with the above given error message and will never return. Any non-xds calls work just fine. I have no way to check the environment on the native library side, but the message indicates that the environment variables are not shared anymore.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 22, 2022
@Falco20019
Copy link
Author

@akoeplinger I assume this should be os-android.

@akoeplinger akoeplinger added os-android and removed untriaged New issue has not been triaged by the area owner labels Jun 22, 2022
@ghost
Copy link

ghost commented Jun 22, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I just ported a Android library from MonoAndroid to net6-android. Sadly, the library (Grpc.Core.Xamarin) uses environment variables to pass the xds_bootstrap.json path over. There is no other way to set it.

On MonoAndroid, calling Environment.SetEnvironmentVariable("GRPC_XDS_BOOTSTRAP", "...") did work. On net6-android, I get a runtime error from the library:

[DOTNET] [16:39:29 ERR MainFrame] 3149119968 /var/local/git/grpc/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc:707: Failed to create xds client -- channel will remain in TRANSIENT_FAILURE: {"created":"@1655915969.698845100","description":"Environment variables GRPC_XDS_BOOTSTRAP or GRPC_XDS_BOOTSTRAP_CONFIG not defined","file":"/var/local/git/grpc/src/core/ext/xds/xds_client.cc","file_line":2359}

Reproduction Steps

  1. Create Android application using <TargetFramework>net6.0-android</TargetFramework>
  2. Add Grpc.Core.Xamarin using the following lines:
  <!-- Workaround for Grpc.Core.Xamarin -->
  <PropertyGroup>
    <Grpc_SkipNativeLibsCopy>true</Grpc_SkipNativeLibsCopy>
  </PropertyGroup>
  <ItemGroup>
    <!-- Use $(GrpcVersion) once packages are available! -->
    <PackageReference Include="Grpc.Core.Xamarin" Version="2.44.0" GeneratePathProperty="true" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\arm64-v8a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\armeabi-v7a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\x86\libgrpc_csharp_ext.so" />
  </ItemGroup>
  1. Try to call any endpoint with a target that uses xds:///

Expected behavior

The call should be made using xDS name resolution.

Actual behavior

The call failed with the above given error message and will never return. Any non-xds calls work just fine. I have no way to check the environment on the native library side, but the message indicates that the environment variables are not shared anymore.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: Falco20019
Assignees: -
Labels:

os-android

Milestone: -

@akoeplinger
Copy link
Member

Yep but unfortunately this is expected in .NET 6, environment variables aren't propagated to native code (see the discussion in #9529 for some of the problems)

You can manually P/Invoke into setenv as a workaround.

@ghost
Copy link

ghost commented Jun 22, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I just ported a Android library from MonoAndroid to net6-android. Sadly, the library (Grpc.Core.Xamarin) uses environment variables to pass the xds_bootstrap.json path over. There is no other way to set it.

On MonoAndroid, calling Environment.SetEnvironmentVariable("GRPC_XDS_BOOTSTRAP", "...") did work. On net6-android, I get a runtime error from the library:

[DOTNET] [16:39:29 ERR MainFrame] 3149119968 /var/local/git/grpc/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc:707: Failed to create xds client -- channel will remain in TRANSIENT_FAILURE: {"created":"@1655915969.698845100","description":"Environment variables GRPC_XDS_BOOTSTRAP or GRPC_XDS_BOOTSTRAP_CONFIG not defined","file":"/var/local/git/grpc/src/core/ext/xds/xds_client.cc","file_line":2359}

Reproduction Steps

  1. Create Android application using <TargetFramework>net6.0-android</TargetFramework>
  2. Add Grpc.Core.Xamarin using the following lines:
  <!-- Workaround for Grpc.Core.Xamarin -->
  <PropertyGroup>
    <Grpc_SkipNativeLibsCopy>true</Grpc_SkipNativeLibsCopy>
  </PropertyGroup>
  <ItemGroup>
    <!-- Use $(GrpcVersion) once packages are available! -->
    <PackageReference Include="Grpc.Core.Xamarin" Version="2.44.0" GeneratePathProperty="true" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\arm64-v8a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\armeabi-v7a\libgrpc_csharp_ext.so" />
    <AndroidNativeLibrary Include="$(PkgGrpc_Core_Xamarin)\native\android\x86\libgrpc_csharp_ext.so" />
  </ItemGroup>
  1. Try to call any endpoint with a target that uses xds:///

Expected behavior

The call should be made using xDS name resolution.

Actual behavior

The call failed with the above given error message and will never return. Any non-xds calls work just fine. I have no way to check the environment on the native library side, but the message indicates that the environment variables are not shared anymore.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: Falco20019
Assignees: -
Labels:

area-System.Runtime, os-android

Milestone: -

@akoeplinger akoeplinger closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2022
@Falco20019
Copy link
Author

Thanks for the update. I also came up with invoking it and that indeed solved my issue.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants