fix: Ensure spark config init and login are only performed once
As a static function that could be called from anywhere in the code (directly or indirectly), 'Configuration.Initialize' was vulnerable to race bugs. The "Configuration.get<T>()" method, whose calls are ubiquitous in our code, would initialize config if it hadn't been done so already. Without a reference to the configServer param, this param would effectively be ignored/overridden with null. It's important that login only be performed once, for obvious reasons (our exes that connect to sparkd are generally designed to process data for a single user). Furthermore, not every routine that requires a successful login has a reference to the credentials needed to do it. To address this, we now pass the ISparkdLoginService singleton to these routines so they can wait until the singular login task has completed before they begin.
This commit is contained in:
1 parent
35a45c35ba
commit
6986cb5e8e
4 files changed
+89
-18
No files matched your search
@@ -41,8 +41,10 @@
|
||||
Log.notnull(opts.user);
|
||||
Log.notnull(opts.password);
|
||||
PubSubConfig.SetGlobalConfig(Log.notnull(opts.PubSub));
|
||||
var serviceCtx = new ServiceContext(new SparkConfigLoader(new SparkConfigLoaderOpts() { ConfigServer = opts.sparkd } ));
|
||||
var loginService = new SparkdLoginService(serviceCtx, new SparkApiCredentials() { User = opts.user, Password = opts.password });
|
||||
var cfgLoader = new SparkConfigLoader(new SparkConfigLoaderOpts() { ConfigServer = opts.sparkd } );
|
||||
var serviceCtx = new ServiceContext(cfgLoader);
|
||||
var loginService = new SparkdLoginService(
|
||||
serviceCtx, new SparkApiCredentials() { User = opts.user, Password = opts.password }, cfgLoader);
|
||||
await loginService.LoginAsync();
|
||||
PrimitiveManager.SetMarketDataClient(new MarketDataClient(new(TimeSpan.FromSeconds(0.5))));
|
||||
|
||||
|
||||
Reference in new issue
Block a user