diff options
author | Mark D. Roth <roth@google.com> | 2018-08-17 08:11:10 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2018-08-17 08:11:10 -0700 |
commit | e9e92d443cdb2b9b9cde7f13eb6a426e988df69a (patch) | |
tree | 24c6e432b90114c1a5263b848d525ae3e08d2371 /src/csharp | |
parent | 4d6f002780e936290ddc629a6eb04a95567f5f8a (diff) | |
parent | d19fd1c689b1d60cf329331da7fab5d1ca6063cc (diff) |
Merge remote-tracking branch 'juanlishen/pf_check_state_before_watch' into pf_keep_unselected_subchannels
Diffstat (limited to 'src/csharp')
-rwxr-xr-x | src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/SanityTest.cs | 6 | ||||
-rwxr-xr-x | src/csharp/Grpc.Core/Grpc.Core.csproj | 18 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/GrpcEnvironment.cs | 24 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/PlatformApis.cs | 29 | ||||
-rwxr-xr-x | src/csharp/Grpc.Core/Version.csproj.include | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/build/MonoAndroid10/Grpc.Core.targets (renamed from src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets) | 9 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/build/Xamarin.iOS10/Grpc.Core.targets (renamed from src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets) | 4 | ||||
-rwxr-xr-x | src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj | 4 | ||||
-rwxr-xr-x | src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj | 4 | ||||
-rwxr-xr-x | src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj | 4 | ||||
-rwxr-xr-x | src/csharp/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj | 4 |
12 files changed, 79 insertions, 33 deletions
diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index 18993a93e0..d58f046824 100755 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -17,8 +17,8 @@ <ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> - <PackageReference Include="NUnit" Version="3.6.0" /> - <PackageReference Include="NUnitLite" Version="3.6.0" /> + <PackageReference Include="NUnit" Version="3.10.1" /> + <PackageReference Include="NUnitLite" Version="3.10.1" /> <PackageReference Include="OpenCover" Version="4.6.519" /> <PackageReference Include="ReportGenerator" Version="2.4.4.0" /> </ItemGroup> diff --git a/src/csharp/Grpc.Core.Tests/SanityTest.cs b/src/csharp/Grpc.Core.Tests/SanityTest.cs index 73efad1f84..eaad409ec0 100644 --- a/src/csharp/Grpc.Core.Tests/SanityTest.cs +++ b/src/csharp/Grpc.Core.Tests/SanityTest.cs @@ -65,13 +65,13 @@ namespace Grpc.Core.Tests { foreach (var m in t.GetMethods()) { - var attributes = m.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), true); - if (attributes.Length > 0) + var testAttributes = m.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), true); + var testCaseAttributes = m.GetCustomAttributes(typeof(NUnit.Framework.TestCaseAttribute), true); + if (testAttributes.Length > 0 || testCaseAttributes.Length > 0) { testClasses.Add(t.FullName); break; } - } } testClasses.Sort(); diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index fc32271063..dc5683c975 100755 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -47,35 +47,35 @@ <Pack>true</Pack> </Content> <Content Include="..\nativelibs\csharp_ext_linux_android_armeabi-v7a\libgrpc_csharp_ext.so"> - <PackagePath>runtimes/monoandroid/armeabi-v7a/libgrpc_csharp_ext.so</PackagePath> + <PackagePath>native/android/armeabi-v7a/libgrpc_csharp_ext.so</PackagePath> <Pack>true</Pack> </Content> <Content Include="..\nativelibs\csharp_ext_linux_android_arm64-v8a\libgrpc_csharp_ext.so"> - <PackagePath>runtimes/monoandroid/arm64-v8a/libgrpc_csharp_ext.so</PackagePath> + <PackagePath>native/android/arm64-v8a/libgrpc_csharp_ext.so</PackagePath> <Pack>true</Pack> </Content> <Content Include="..\nativelibs\csharp_ext_linux_android_x86\libgrpc_csharp_ext.so"> - <PackagePath>runtimes/monoandroid/x86/libgrpc_csharp_ext.so</PackagePath> + <PackagePath>native/android/x86/libgrpc_csharp_ext.so</PackagePath> <Pack>true</Pack> </Content> <Content Include="..\nativelibs\csharp_ext_macos_ios\libgrpc_csharp_ext.a"> - <PackagePath>runtimes/ios/native/libgrpc_csharp_ext.a</PackagePath> + <PackagePath>native/ios/universal/libgrpc_csharp_ext.a</PackagePath> <Pack>true</Pack> </Content> <Content Include="..\nativelibs\csharp_ext_macos_ios\libgrpc.a"> - <PackagePath>runtimes/ios/native/libgrpc.a</PackagePath> + <PackagePath>native/ios/universal/libgrpc.a</PackagePath> <Pack>true</Pack> </Content> <Content Include="build\net45\Grpc.Core.targets"> <PackagePath>build/net45/</PackagePath> <Pack>true</Pack> </Content> - <Content Include="build\MonoAndroid\Grpc.Core.targets"> - <PackagePath>build/MonoAndroid/</PackagePath> + <Content Include="build\MonoAndroid10\Grpc.Core.targets"> + <PackagePath>build/MonoAndroid10/</PackagePath> <Pack>true</Pack> </Content> - <Content Include="build\Xamarin.iOS\Grpc.Core.targets"> - <PackagePath>build/Xamarin.iOS/</PackagePath> + <Content Include="build\Xamarin.iOS10\Grpc.Core.targets"> + <PackagePath>build/Xamarin.iOS10/</PackagePath> <Pack>true</Pack> </Content> </ItemGroup> diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs index a6a1d8af50..6ca694e0e4 100644 --- a/src/csharp/Grpc.Core/GrpcEnvironment.cs +++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs @@ -50,6 +50,7 @@ namespace Grpc.Core static int requestCallContextPoolThreadLocalCapacity = DefaultRequestCallContextPoolThreadLocalCapacity; static readonly HashSet<Channel> registeredChannels = new HashSet<Channel>(); static readonly HashSet<Server> registeredServers = new HashSet<Server>(); + static readonly AtomicCounter nativeInitCounter = new AtomicCounter(); static ILogger logger = new LogLevelFilterLogger(new ConsoleLogger(), LogLevel.Off, true); @@ -360,12 +361,25 @@ namespace Grpc.Core internal static void GrpcNativeInit() { + if (!IsNativeShutdownAllowed && nativeInitCounter.Count > 0) + { + // Normally grpc_init and grpc_shutdown calls should come in pairs (C core does reference counting), + // but in case we avoid grpc_shutdown calls altogether, calling grpc_init has no effect + // besides incrementing an internal C core counter that could theoretically overflow. + // To avoid this theoretical possibility we guard repeated calls to grpc_init() + // with a 64-bit atomic counter (that can't realistically overflow). + return; + } NativeMethods.Get().grpcsharp_init(); + nativeInitCounter.Increment(); } internal static void GrpcNativeShutdown() { - NativeMethods.Get().grpcsharp_shutdown(); + if (IsNativeShutdownAllowed) + { + NativeMethods.Get().grpcsharp_shutdown(); + } } /// <summary> @@ -411,6 +425,14 @@ namespace Grpc.Core return GetThreadPoolSizeOrDefault(); } + // On some platforms (specifically iOS), thread local variables in native code + // require initialization/destruction. By skipping the grpc_shutdown() call, + // we avoid a potential crash where grpc_shutdown() has already destroyed + // the thread local variables, but some C core's *_destroy() methods still + // need to run (e.g. they may be run by finalizer thread which is out of our control) + // For more context, see https://github.com/grpc/grpc/issues/16294 + private static bool IsNativeShutdownAllowed => !PlatformApis.IsXamarinIOS && !PlatformApis.IsUnityIOS; + private static class ShutdownHooks { static object staticLock = new object(); diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs index c501aa89fb..a8f147545b 100644 --- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs +++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs @@ -42,6 +42,7 @@ namespace Grpc.Core.Internal static readonly bool isMono; static readonly bool isNetCore; static readonly bool isUnity; + static readonly bool isUnityIOS; static readonly bool isXamarin; static readonly bool isXamarinIOS; static readonly bool isXamarinAndroid; @@ -63,7 +64,25 @@ namespace Grpc.Core.Internal isNetCore = false; #endif isMono = Type.GetType("Mono.Runtime") != null; - isUnity = Type.GetType(UnityEngineApplicationClassName) != null; + + // Unity + var unityApplicationClass = Type.GetType(UnityEngineApplicationClassName); + if (unityApplicationClass != null) + { + isUnity = true; + // Consult value of Application.platform via reflection + // https://docs.unity3d.com/ScriptReference/Application-platform.html + var platformProperty = unityApplicationClass.GetTypeInfo().GetProperty("platform"); + var unityRuntimePlatform = platformProperty?.GetValue(null)?.ToString(); + isUnityIOS = (unityRuntimePlatform == "IPhonePlayer"); + } + else + { + isUnity = false; + isUnityIOS = false; + } + + // Xamarin isXamarinIOS = Type.GetType(XamarinIOSObjectClassName) != null; isXamarinAndroid = Type.GetType(XamarinAndroidObjectClassName) != null; isXamarin = isXamarinIOS || isXamarinAndroid; @@ -98,6 +117,14 @@ namespace Grpc.Core.Internal } /// <summary> + /// true if running on Unity iOS, false otherwise. + /// </summary> + public static bool IsUnityIOS + { + get { return isUnityIOS; } + } + + /// <summary> /// true if running on a Xamarin platform (either Xamarin.Android or Xamarin.iOS), /// false otherwise. /// </summary> diff --git a/src/csharp/Grpc.Core/Version.csproj.include b/src/csharp/Grpc.Core/Version.csproj.include index 6b0731eb40..45bd8ebd85 100755 --- a/src/csharp/Grpc.Core/Version.csproj.include +++ b/src/csharp/Grpc.Core/Version.csproj.include @@ -2,6 +2,6 @@ <Project> <PropertyGroup> <GrpcCsharpVersion>1.15.0-dev</GrpcCsharpVersion> - <GoogleProtobufVersion>3.6.0</GoogleProtobufVersion> + <GoogleProtobufVersion>3.6.1</GoogleProtobufVersion> </PropertyGroup> </Project> diff --git a/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets b/src/csharp/Grpc.Core/build/MonoAndroid10/Grpc.Core.targets index d75e5a2f2f..250d3bd0cd 100644 --- a/src/csharp/Grpc.Core/build/MonoAndroid/Grpc.Core.targets +++ b/src/csharp/Grpc.Core/build/MonoAndroid10/Grpc.Core.targets @@ -1,25 +1,22 @@ <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <_GrpcCoreNugetNativePath Condition="'$(_GrpcCoreNugetNativePath)' == ''">$(MSBuildThisFileDirectory)..\..\</_GrpcCoreNugetNativePath> - </PropertyGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'"> - <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\arm64-v8a\libgrpc_csharp_ext.so"> + <AndroidNativeLibrary Include="$(MSBuildThisFileDirectory)..\..\native\android\arm64-v8a\libgrpc_csharp_ext.so"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Abi>arm64-v8a</Abi> </AndroidNativeLibrary> </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'"> - <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\armeabi-v7a\libgrpc_csharp_ext.so"> + <AndroidNativeLibrary Include="$(MSBuildThisFileDirectory)..\..\native\android\armeabi-v7a\libgrpc_csharp_ext.so"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Abi>armeabi-v7a</Abi> </AndroidNativeLibrary> </ItemGroup> <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'"> - <AndroidNativeLibrary Include="$(_GrpcCoreNugetNativePath)runtimes\monoandroid\x86\libgrpc_csharp_ext.so"> + <AndroidNativeLibrary Include="$(MSBuildThisFileDirectory)..\..\native\android\x86\libgrpc_csharp_ext.so"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Abi>x86</Abi> </AndroidNativeLibrary> diff --git a/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets b/src/csharp/Grpc.Core/build/Xamarin.iOS10/Grpc.Core.targets index 658158f6ea..dda1cdd1e8 100644 --- a/src/csharp/Grpc.Core/build/Xamarin.iOS/Grpc.Core.targets +++ b/src/csharp/Grpc.Core/build/Xamarin.iOS10/Grpc.Core.targets @@ -2,11 +2,11 @@ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> - <NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\libgrpc_csharp_ext.a"> + <NativeReference Include="$(MSBuildThisFileDirectory)..\..\native\ios\universal\libgrpc_csharp_ext.a"> <Kind>Static</Kind> <ForceLoad>True</ForceLoad> </NativeReference> - <NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\libgrpc.a"> + <NativeReference Include="$(MSBuildThisFileDirectory)..\..\native\ios\universal\libgrpc.a"> <Kind>Static</Kind> <ForceLoad>True</ForceLoad> </NativeReference> diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj index d2cc5bbc65..7493eb8051 100755 --- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj +++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj @@ -17,8 +17,8 @@ </ItemGroup> <ItemGroup> - <PackageReference Include="NUnit" Version="3.6.0" /> - <PackageReference Include="NUnitLite" Version="3.6.0" /> + <PackageReference Include="NUnit" Version="3.10.1" /> + <PackageReference Include="NUnitLite" Version="3.10.1" /> <PackageReference Include="Moq" Version="4.8.2" /> </ItemGroup> diff --git a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj index 9da0539dcb..616e56df10 100755 --- a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj +++ b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj @@ -16,8 +16,8 @@ </ItemGroup> <ItemGroup> - <PackageReference Include="NUnit" Version="3.6.0" /> - <PackageReference Include="NUnitLite" Version="3.6.0" /> + <PackageReference Include="NUnit" Version="3.10.1" /> + <PackageReference Include="NUnitLite" Version="3.10.1" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index e4f36d8810..ad7033b782 100755 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -19,8 +19,8 @@ <ItemGroup> <PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufVersion)" /> <PackageReference Include="CommandLineParser" Version="2.1.1-beta" /> - <PackageReference Include="NUnit" Version="3.6.0" /> - <PackageReference Include="NUnitLite" Version="3.6.0" /> + <PackageReference Include="NUnit" Version="3.10.1" /> + <PackageReference Include="NUnitLite" Version="3.10.1" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> diff --git a/src/csharp/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj b/src/csharp/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj index d368697124..0c12f38f25 100755 --- a/src/csharp/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj +++ b/src/csharp/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj @@ -16,8 +16,8 @@ </ItemGroup> <ItemGroup> - <PackageReference Include="NUnit" Version="3.6.0" /> - <PackageReference Include="NUnitLite" Version="3.6.0" /> + <PackageReference Include="NUnit" Version="3.10.1" /> + <PackageReference Include="NUnitLite" Version="3.10.1" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> |