remove readonly of AuthenticationConnection in Session#844
remove readonly of AuthenticationConnection in Session#844wizicer wants to merge 1 commit intosshnet:masterfrom
Conversation
SetSshNetConcurrency(100); public static void SetSshNetConcurrency(int concurrency)
{
var field = typeof(Renci.SshNet.Session).GetField("AuthenticationConnection",
BindingFlags.Static |
BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(null, new SemaphoreLight(concurrency));
}
}Utilize this to change it at startup. It works for me flawlessly. |
|
Why are this and other PR's not being checked in. Is the project dead? |
|
@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. |
|
Unfortunately the workaround above does not work on .NET Core 3+ due to dotnet/runtime#11571. Instead, you can do this var sessionSemaphoreField = typeof(Renci.SshNet.Session)
.GetField("AuthenticationConnection", BindingFlags.Static | BindingFlags.NonPublic);
var semaphoreCountField = typeof(Renci.SshNet.Common.SemaphoreLight)
.GetField("_currentCount", BindingFlags.Instance | BindingFlags.NonPublic);
object semaphore = sessionSemaphoreField.GetValue(null);
semaphoreCountField.SetValue(semaphore, concurrency);or this, since var sessionSemaphoreField = typeof(Renci.SshNet.Session)
.GetField("AuthenticationConnection", BindingFlags.Static | BindingFlags.NonPublic);
var semaphore = (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); |
|
@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. |
|
The AuthenticationConnection semaphore has been removed in #1304 |
|
This issue has been fixed in the 2024.0.0 version. |
remove
readonlyofAuthenticationConnectionin Session to support customize parallel connecting number.Related Issues:
#215
#264
#409
#840