From 198f778d65a728c2c637596fe8fbd05c8ac223d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 25 Aug 2019 17:52:35 +0200 Subject: [PATCH] Troubleshooting --- Capnp.Net.Runtime/Rpc/Impatient.cs | 26 ++++++++++++++----- .../Rpc/RefCountingCapability.cs | 9 +++---- appveyor.yml | 4 +-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Capnp.Net.Runtime/Rpc/Impatient.cs b/Capnp.Net.Runtime/Rpc/Impatient.cs index dc278ae..5dfabd2 100644 --- a/Capnp.Net.Runtime/Rpc/Impatient.cs +++ b/Capnp.Net.Runtime/Rpc/Impatient.cs @@ -33,14 +33,26 @@ namespace Capnp.Rpc // Really weird: We'd expect AwaitAnswer() to initialize a new Task instance upon each invocation. // However, this does not seem to be always true (as indicated by CI test suite). An explanation might be - // that the underlying implementation recycles Task instances. Let's work around it. + // that the underlying implementation recycles Task instances (um, really? doesn't make sense. But the + // obsevation doesn't make sense, either). -#if NETSTANDARD2_0 - _taskTable.Remove(rtask); - _taskTable.Add(rtask, promise); -#else - _taskTable.AddOrUpdate(rtask, promise); -#endif + try + { + _taskTable.Add(rtask, promise); + } + catch (ArgumentException) + { + // Force .NET to create a new Task instance + + async Task AwaitAgain() + { + return await rtask; + } + + rtask = AwaitAgain(); + + _taskTable.Add(rtask, promise); + } return rtask; } diff --git a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs index 61faf4b..37a1283 100644 --- a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs @@ -23,7 +23,6 @@ namespace Capnp.Rpc // In order to distinguish state A from C, the member _refCount stores the reference count *plus one*. // Value 0 has the special meaning of being in state C. int _refCount = 1; - string _disposerStackTrace; ~RefCountingCapability() { @@ -37,6 +36,8 @@ namespace Capnp.Rpc { if (disposing) { + _refCount = 0; + try { ReleaseRemotely(); @@ -44,8 +45,6 @@ namespace Capnp.Rpc catch { } - - _refCount = 0; } else { @@ -69,7 +68,7 @@ namespace Capnp.Rpc { if (Interlocked.Increment(ref _refCount) <= 1) { - throw new ObjectDisposedException(nameof(ConsumedCapability), _disposerStackTrace); + throw new ObjectDisposedException(nameof(ConsumedCapability)); } } @@ -77,8 +76,6 @@ namespace Capnp.Rpc { if (1 >= Interlocked.Decrement(ref _refCount)) { - _disposerStackTrace = Environment.StackTrace; - Dispose(true); GC.SuppressFinalize(this); } diff --git a/appveyor.yml b/appveyor.yml index d8cf49e..133d24e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,10 +38,10 @@ build_script: after_build: # For once the build has completed artifacts: - - path: Capnp.Net.Runtime\bin\Debug + - path: Capnp.Net.Runtime\bin\Debug\Capnp.Net.Runtime.$(appveyor_build_version).nupkg name: Capnp.Net.Runtime_debug type: NuGetPackage - - path: Capnp.Net.Runtime\bin\Release + - path: Capnp.Net.Runtime\bin\Release\Capnp.Net.Runtime.$(appveyor_build_version).nupkg name: Capnp.Net.Runtime type: NuGetPackage - path: chocolatey\install\capnpc-csharp-win-x86.$(appveyor_build_version).nupkg