Catch exceptions on AsyncTCPConnector_AsyncWrapper background thread
Since it spawns a new thread on each attempt, uncaught exceptions were previously undetected, and caused silent failures down the pipe. This should make it easier to track such bugs down.
This commit is contained in:
1 parent
be7148dcec
commit
dbf941ff0e
2 files changed
+12
-3
No files matched your search
@@ -49,7 +49,7 @@ namespace BCG {
|
||||
|
||||
public RemoteConnectionInfo get_pub_route_for_tag(string tag) {
|
||||
if (!_pub_routes.TryGetFirst(r => r?.IsMatch(tag) ?? false, out var route)) {
|
||||
throw new ArgumentException($"Failed to find route for tag '{tag}'", nameof(tag));
|
||||
Log.assert(false, $"Failed to find route for tag '{tag}'", nameof(tag));
|
||||
}
|
||||
Log.Gen.info($"PubSubRouter.get_sub_url_for_tag tag: {tag} route: {JsonSerializer.Serialize(route)}");
|
||||
ArgumentNullException.ThrowIfNull(route.ServerAddress);
|
||||
@@ -58,7 +58,7 @@ namespace BCG {
|
||||
|
||||
public RemoteConnectionInfo get_sub_route_for_tag(string tag) {
|
||||
if (!_sub_routes.TryGetFirst(r => r?.IsMatch(tag) ?? false, out var route)) {
|
||||
throw new ArgumentException($"Failed to find route for tag '{tag}'", nameof(tag));
|
||||
Log.assert(false, $"Failed to find route for tag '{tag}'", nameof(tag));
|
||||
}
|
||||
Log.Gen.info($"PubSubRouter.get_sub_url_for_tag tag: {tag} route: {JsonSerializer.Serialize(route)}");
|
||||
ArgumentNullException.ThrowIfNull(route.ServerAddress);
|
||||
|
||||
@@ -19,7 +19,16 @@ namespace bts {
|
||||
bts.Log.Gen.info($"AsyncTCPConnector_AsyncWrapper.connect_to server: {server_address}");
|
||||
//Task.Run(() => _connect_to(server_address, handler));
|
||||
ThreadPool.QueueUserWorkItem(_ => _keep_trying_blocking_function(
|
||||
() => _connect_to(server_address, handler), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)));
|
||||
Connect, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)));
|
||||
|
||||
bool Connect() {
|
||||
try {
|
||||
return _connect_to(server_address, handler);
|
||||
} catch (Exception ex) {
|
||||
Log.assert(false, $"AsyncTCPConnector_AsyncWrapper connect threw exception: {ex}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this is the actual fuction thta calls TCPCLient sync methof and establishes a connection
|
||||
|
||||
Reference in new issue
Block a user