Comments (5)
Hi,
Thanks for the report! So we can best assist you, could you please follow the issue template with your info? Thanks!
If I call Acquire method with an already cancelled token I get a Null Reference Exception from whitin the consul library.
This would be a bug. Feel free to share a repro code (or unit test) :-)
Can you please explain why the cancellation token is not passed?
No reason, it may have been overlooked. Could you share a repro/unit test for this as well please?
Thanks.
from consuldotnet.
Hi again!
Thank you for your response!
Here are the unit tests. Please note, that if you run them all at once, one might fail because the lock entry doesn't clean up always from consul agent. However, if you make sure there is no lock session before each test runs they all pass.
Consuldotnet v 1.6.1.1
OS: Windows
namespace XUnitTestProject1
{
using Consul;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
public class LockTest
{
private readonly string key = "service/myApp/leader";
private readonly Uri _uri = new Uri("http://consul:8500");
private readonly LockOptions _lockOptions;
private readonly ConsulClient _slaveInstanceClient;
private readonly ConsulClient _masterInstanceClient;
private const int DefaultSessionTTLSeconds = 10;
private const int LockWaitTimeSeconds = 15;
public LockTest()
{
_lockOptions = new LockOptions(key)
{
SessionTTL = TimeSpan.FromSeconds(DefaultSessionTTLSeconds),
LockWaitTime = TimeSpan.FromSeconds(LockWaitTimeSeconds)
};
_slaveInstanceClient = new ConsulClient(c => c.Address = _uri);
_masterInstanceClient = new ConsulClient(c => c.Address = _uri);
}
[Fact]
public async Task Passing_Cancelled_CancellationToken_Throws_NullReferenceEx()
{
// Arrange
var distributedLock = _slaveInstanceClient.CreateLock(_lockOptions);
var cts = new CancellationTokenSource();
// Act
cts.Cancel();
// Assert
await Assert.ThrowsAsync < NullReferenceException >(async () =>
await distributedLock.Acquire(cts.Token));
}
[Fact]
public async Task Cancelling_A_Token_When_Acquiring_A_Lock_Throws_NullReferenceEx()
{
// Arrange
var distributedLock2 = _masterInstanceClient.CreateLock(_lockOptions);
var distributedLock = _slaveInstanceClient.CreateLock(_lockOptions);
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
// Act
await distributedLock2.Acquire(); // Become "Master" with another instance first
var task = distributedLock.Acquire(cts.Token);
// Assert
await Assert.ThrowsAsync < NullReferenceException >(async () => await task);
// cleanup
await distributedLock2.Release();
if (distributedLock.IsHeld)
await distributedLock2.Release();
await distributedLock2.Destroy();
}
[Fact]
public async Task Cancelling_A_Token_When_Acquiring_A_Lock_Doesnt_Respect_Token()
{
// Arrange
var distributedLock2 = _masterInstanceClient.CreateLock(_lockOptions);
var distributedLock = _slaveInstanceClient.CreateLock(_lockOptions);
var cancellationOperationTimer = new Stopwatch();
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
// Act
await distributedLock2.Acquire(); // Become "Master" with another instance first
cancellationOperationTimer.Start();
try
{
await distributedLock.Acquire(cts.Token);
}
catch (Exception) { }
cancellationOperationTimer.Stop();
// Assert
var stopTimeMs = cancellationOperationTimer.ElapsedMilliseconds;
var LockWaitTimeMs = TimeSpan.FromSeconds(LockWaitTimeSeconds).TotalMilliseconds;
Assert.True(stopTimeMs > LockWaitTimeMs);
// cleanup
await distributedLock2.Release();
if (distributedLock.IsHeld)
await distributedLock2.Release();
await distributedLock2.Destroy();
}
}
}
from consuldotnet.
Great, thanks.
Would you mind pushing them to a branch on your fork and sharing it here, please? This will be easier to retrieve and run locally for the maintainers :-)
from consuldotnet.
Please try https://www.nuget.org/packages/Consul/1.6.10.1-rc1
from consuldotnet.
Hi, Today I updated to the latest version of the package and the issues are resolved. Thanks!
from consuldotnet.
Related Issues (20)
- [CI Bug]: Consul.Test.TokenTest.Token_CreateWithServiceIdentitiesDelete is flaky
- How to delete all keys? HOT 4
- [CI] Fix deprecation warnings HOT 1
- Is the class ConsulClient thread safe? HOT 1
- Cannot create an associated check for a service with custom check id HOT 5
- [Bug]: ServiceRegister does not pass WriteOptions to PutRequest, resulting in missing token and datacenter HOT 1
- [Bug]: Consul.Test.SemaphoreTest.Semaphore_OneShot is flaky
- [Bug]: System.IO.IOException: The response ended prematurely HOT 5
- Add `ServiceTags` field to the health endpoint response
- Table showing missing features in consuldotnet
- Add support for Agent Host
- Support for Agent Version Information
- Support for Agent Metrics
- Added Test for Agent Reload
- Support Applying Configuration and Get Configuration
- Support Listing and Deleting Configuration Entries
- Support for Listing Services for Node and Retrieving Nodes that support Mesh Capable Service
- Support Getting Service Configuration
- Wanna do some contribution HOT 1
- [FEATURE REQUEST]: support weights option
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from consuldotnet.