Troubleshooting ReleaseOnCancelClient

This commit is contained in:
Christian Köllner 2019-08-25 16:33:28 +02:00
parent e6c129b8da
commit 0140f21cc4

View File

@ -23,6 +23,7 @@ namespace Capnp.Rpc
// In order to distinguish state A from C, the member _refCount stores the reference count *plus one*. // 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. // Value 0 has the special meaning of being in state C.
int _refCount = 1; int _refCount = 1;
string _disposerStackTrace;
~RefCountingCapability() ~RefCountingCapability()
{ {
@ -68,7 +69,7 @@ namespace Capnp.Rpc
{ {
if (Interlocked.Increment(ref _refCount) <= 1) if (Interlocked.Increment(ref _refCount) <= 1)
{ {
throw new ObjectDisposedException(nameof(ConsumedCapability)); throw new ObjectDisposedException(nameof(ConsumedCapability), _disposerStackTrace);
} }
} }
@ -76,6 +77,8 @@ namespace Capnp.Rpc
{ {
if (1 >= Interlocked.Decrement(ref _refCount)) if (1 >= Interlocked.Decrement(ref _refCount))
{ {
_disposerStackTrace = Environment.StackTrace;
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }