Skip to content

Commit f868b89

Browse files
authored
Fix race condition in GetOrCreateBoundConfiguration (#178)
1 parent 1e3422b commit f868b89

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Elastic.Transport/DistributedTransport.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,20 @@ BoundConfiguration GetOrCreateBoundConfiguration(RequestConfiguration rc)
305305
return boundConfiguration;
306306
}
307307

308+
#if NET8_0_OR_GREATER
308309
boundConfiguration = new BoundConfiguration(Configuration, rc);
309310

310-
#if NET8_0_OR_GREATER
311311
cache.TryAdd(rc, boundConfiguration);
312312
#else
313313
lock (cache)
314314
{
315+
if (cache.TryGetValue(rc, out boundConfiguration))
316+
{
317+
return boundConfiguration;
318+
}
319+
320+
boundConfiguration = new BoundConfiguration(Configuration, rc);
321+
315322
cache.Add(rc, boundConfiguration);
316323
}
317324
#endif

0 commit comments

Comments
 (0)