Skip to content
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 race condition with protocol extensions #101

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/cs/Ssh/IO/SshProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public SshProtocol(

internal bool TraceChannelData { get; set; }

internal Dictionary<string, string>? Extensions { get; set; }
internal IReadOnlyDictionary<string, string>? Extensions { get; set; }

internal KeyExchangeService? KeyExchangeService { get; set; }

Expand Down
12 changes: 8 additions & 4 deletions src/cs/Ssh/SshSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,23 +1475,27 @@ internal async Task HandleMessageAsync(
return;
}

Protocol.Extensions = new Dictionary<string, string>();

var proposedExtensions = message.ExtensionInfo;
if (proposedExtensions == null)
{
Protocol.Extensions = new Dictionary<string, string>();
return;
}

// Fill the extensions dictionary with only the extensions that are enabled.
// Assign to the Protocol.Extensions property only after it is filled to avoid a race.
Dictionary<string, string> extensions = new Dictionary<string, string>();
foreach (var extensionName in Config.ProtocolExtensions)
{
if (proposedExtensions.TryGetValue(extensionName, out var value))
{
Protocol.Extensions.Add(extensionName, value);
extensions.Add(extensionName, value);
}
}

if (Protocol.Extensions.ContainsKey(SshProtocolExtensionNames.SessionReconnect))
Protocol.Extensions = extensions;

if (extensions.ContainsKey(SshProtocolExtensionNames.SessionReconnect))
{
// Reconnect is not enabled until each side sends a special request message.
await EnableReconnectAsync(cancellation).ConfigureAwait(false);
Expand Down
Loading