From e2556fae85af0f6bd8ee69a05bde4d38e94d8032 Mon Sep 17 00:00:00 2001 From: Martin Lee Date: Wed, 26 Feb 2020 09:59:17 +0000 Subject: [PATCH] Remove locking. Unforseen deadlock --- SuccessfulCodeTools/LowLevelHttpClient/CustomHttpClient.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SuccessfulCodeTools/LowLevelHttpClient/CustomHttpClient.cs b/SuccessfulCodeTools/LowLevelHttpClient/CustomHttpClient.cs index 7bc6152..e24395b 100644 --- a/SuccessfulCodeTools/LowLevelHttpClient/CustomHttpClient.cs +++ b/SuccessfulCodeTools/LowLevelHttpClient/CustomHttpClient.cs @@ -17,7 +17,6 @@ namespace SuccessfulCodeTools.LowLevelHttpClient { public int? OutgoingPort { get; set; } public KeyValueCollection DefaultHeaders = new KeyValueCollection(); - private static readonly ConcurrentDictionary _dictionary = new ConcurrentDictionary(); public CustomHttpClient(int? outgoingPort = null) { OutgoingPort = outgoingPort; @@ -30,8 +29,7 @@ namespace SuccessfulCodeTools.LowLevelHttpClient message.Headers.AddRange(defaultHeaders); var outBoundPort = outgoingPort ?? OutgoingPort ?? 0; - var semphoreLock = (SemaphoreSlim)_dictionary.GetOrAdd(outBoundPort, e => new SemaphoreSlim(1)); - semphoreLock.Wait(); + var ipLocalEndPoint = new IPEndPoint(IPAddress.Any, outBoundPort); using (var tcp = new TcpClient(ipLocalEndPoint)) { @@ -60,7 +58,6 @@ namespace SuccessfulCodeTools.LowLevelHttpClient tcp.Client.Disconnect(true); stream.Close(); tcp.Client.Close(); - semphoreLock.Release(); return new CustomHttpResponseMessage(memory); } }