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
fix(ws): fix #22037 - concurrent subscription requests #22309
fix(ws): fix #22037 - concurrent subscription requests #22309
Conversation
@pcriadoperez tryAdd is not available by using the interface, we need the proper type |
@pcriadoperez did you test the demo provided by the user? I get inconsistent results with this PR (sometimes we subscribe to both sometimes we don't) public class Demo22037
{
public async Task Run()
{
var exchange = new ccxt.pro.Bitget();
exchange.apiKey = Environment.GetEnvironmentVariable("BITGET_APIKEY");
exchange.secret = Environment.GetEnvironmentVariable("BITGET_SECRET");
exchange.password = Environment.GetEnvironmentVariable("BITGET_PASSWORD");
exchange.verbose = true;
var task1 = Task.Run(async () =>
{
try
{
Dictionary<string, object> _balanceParams = new Dictionary<string, object>();
_balanceParams.Add("type", "spot");
var balanceSpot = await exchange.WatchBalance(_balanceParams);
Console.WriteLine("spot received");
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
var task2 = Task.Run(async () =>
{
try
{
Dictionary<string, object> _balanceParams = new Dictionary<string, object>();
_balanceParams.Add("type", "future");
var balanceFuture = await exchange.WatchBalance(_balanceParams);
Console.WriteLine("future received");
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
Task.WhenAll(task1, task2).Wait();
}
} |
haha these race conditions... 😅 After the first change, it seemed to be working and fixed one race condition but after your comment I tried putting in some Console.WriteLines and the second race condition appeared. With these changes I ran it several times and seems to be working consistently so far. Hopefully cought all of them |
@pcriadoperez Yeah I think it's working now |
* fix(ws): fix #22037 - concurrent subscription requests * trigger build * explitict cast * fix second race condition * add changes for watch multiple * build fix * build fix --------- Co-authored-by: carlosmiei <43336371+carlosmiei@users.noreply.github.com> [ci skip]
Any edits to this.clients, client.futures and client.subscriptions change to use ConcurrentyDictionary methods