Skip to content

remove readonly of AuthenticationConnection in Session - #844

Closed
wizicer wants to merge 1 commit into
sshnet:masterfrom
wizicer:master
Closed

remove readonly of AuthenticationConnection in Session#844
wizicer wants to merge 1 commit into
sshnet:masterfrom
wizicer:master

Conversation

@wizicer

Copy link
Copy Markdown

remove readonly of AuthenticationConnection in Session to support customize parallel connecting number.

Related Issues:
#215
#264
#409
#840

@wizicer

Copy link
Copy Markdown
Author
SetSshNetConcurrency(100);
publicstaticvoidSetSshNetConcurrency(intconcurrency){varfield=typeof(Renci.SshNet.Session).GetField("AuthenticationConnection",BindingFlags.Static|BindingFlags.NonPublic);if(field!=null){field.SetValue(null,newSemaphoreLight(concurrency));}}

Utilize this to change it at startup. It works for me flawlessly.

@xantari

Copy link
Copy Markdown

Why are this and other PR's not being checked in. Is the project dead?

@drieseng

Copy link
Copy Markdown
Member

@xantari because I don't have time and because this is clearly a hack. I'm open to alternate proposals but can't promise that I'll immediately find time to discuss them.

@ascott18

Copy link
Copy Markdown

Unfortunately the workaround above does not work on .NET Core 3+ due to dotnet/runtime#11571.

Instead, you can do this

varsessionSemaphoreField=typeof(Renci.SshNet.Session).GetField("AuthenticationConnection",BindingFlags.Static|BindingFlags.NonPublic);varsemaphoreCountField=typeof(Renci.SshNet.Common.SemaphoreLight).GetField("_currentCount",BindingFlags.Instance|BindingFlags.NonPublic);objectsemaphore=sessionSemaphoreField.GetValue(null);semaphoreCountField.SetValue(semaphore,concurrency);

or this, since SemaphoreLight does not validate against its provided initialCount:

varsessionSemaphoreField=typeof(Renci.SshNet.Session).GetField("AuthenticationConnection",BindingFlags.Static|BindingFlags.NonPublic);varsemaphore=(Renci.SshNet.Common.SemaphoreLight)sessionSemaphoreField.GetValue(null);// Add a much higher count to the semaphore to prevent pointless blocking of connection attempts.semaphore.Release(100);

@ascott18

Copy link
Copy Markdown

@drieseng I would suggest that the proposal in this comment is the best solution - to remove this semaphore outright and leave throttling as a concern of the calling application.

@Rob-Hague

Copy link
Copy Markdown
Collaborator

The AuthenticationConnection semaphore has been removed in #1304

@WojciechNagorski

Copy link
Copy Markdown
Collaborator

This issue has been fixed in the 2024.0.0 version.

@WojciechNagorskiWojciechNagorski added this to the 2024.0.0 milestone Feb 22, 2024
Sign up for freeto 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.

7 participants

@wizicer@xantari@drieseng@ascott18@Rob-Hague@WojciechNagorski@jgauthier350