Skip to content

[release/8.0-staging] Catch exception when subscribing to NetworkChange #95123

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

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,29 @@ public void StartMonitoringNetworkChanges()
return;
}

using (ExecutionContext.SuppressFlow())
// RFC: https://tools.ietf.org/html/rfc7838#section-2.2
// When alternative services are used to send a client to the most
// optimal server, a change in network configuration can result in
// cached values becoming suboptimal. Therefore, clients SHOULD remove
// from cache all alternative services that lack the "persist" flag with
// the value "1" when they detect such a change, when information about
// network state is available.
try
{
using (ExecutionContext.SuppressFlow())
{
NetworkChange.NetworkAddressChanged += networkChangedDelegate;
}
}
catch (NetworkInformationException e)
{
NetworkChange.NetworkAddressChanged += networkChangedDelegate;
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(this, $"Exception when subscribing to NetworkChange.NetworkAddressChanged: {e}");

// We can't monitor network changes, so technically "information
// about network state is not available" and we can just keep
// all Alt-Svc entries until their expiration time.
//
// keep the _networkChangeCleanup field assigned so we don't try again needlessly
}
}

Expand Down