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

Tweak semaphore usage in Session #1304

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

Rob-Hague
Copy link
Collaborator

@Rob-Hague Rob-Hague commented Feb 3, 2024

  • Change _connectAndLazySemaphoreInitLock to a SemaphoreSlim and use it in ConnectAsync.
  • Rename it to _connectLock and only use it for connecting. Replace its other usages (on SessionSemaphore and NextChannelNumber) with Interlocked operations.
  • Remove AuthenticationConnection semaphore. This static member placed a process-wide limit on the number of connections an application can make. I agree with the argument in Effective concurrent SshClient connections bumps into a limit #409 (comment) (and in several other issues/PRs) that this should not be something that the library attempts to control.

The last change broke a few tests which do things like making 100 connections (exceeding OpenSSH MaxStartups value). I was tempted to delete these tests as I don't think they have much value, but instead I just limited their concurrency.

Best viewed with "Hide whitespace"

- Change _connectAndLazySemaphoreInitLock to a SemaphoreSlim and use it in
  ConnectAsync.
- Rename it to _connectLock and only use it for connecting. Replace its
  other usages (on SessionSemaphore and NextChannelNumber) with Interlocked
  operations.
- Remove AuthenticationConnection semaphore. This static member placed a
  process-wide limit on the number of connections an application can make.
  I agree with the argument in
  sshnet#409 (comment)
  (and in several other issues/PRs) that this should not be something
  that the library attempts to control.

The last change broke a few tests which do things like making 100 connections.
I was tempted to delete these tests as I don't think they have much value, but
instead I just limited their concurrency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants