Skip to content

Commit

Permalink
TorClient: use thread-safe collection for guards
Browse files Browse the repository at this point in the history
This commit changes the list type used for storing guard that
need to be destroyed to a thread-safe option this removes the
need for locking the list which according to experience causes
it's own problems.
  • Loading branch information
aarani committed Oct 28, 2023
1 parent 394e101 commit 20413b3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions NOnion/Client/TorClient.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NOnion.Client

open System
open System.Collections.Concurrent
open System.IO
open System.Net
open System.Net.Http
Expand Down Expand Up @@ -72,8 +73,7 @@ type TorClient internal (directory: TorDirectory) =
return new TorClient(directory)
}

//FIXME: lock this
let mutable guardsToDispose: List<TorGuard> = List.empty
let guardsToDispose = ConcurrentBag<TorGuard>()

static member AsyncBootstrapWithEmbeddedList() =
async {
Expand Down Expand Up @@ -124,7 +124,7 @@ type TorClient internal (directory: TorDirectory) =
ipEndPoint
(nodeDetail.GetIdentityKey() |> Some)

guardsToDispose <- guard :: guardsToDispose
guardsToDispose.Add guard
return guard, nodeDetail
with
| :? GuardConnectionFailedException ->
Expand Down

0 comments on commit 20413b3

Please sign in to comment.