From 25523d1985639712c23078ef25e83a2faec9f1b7 Mon Sep 17 00:00:00 2001 From: Xin Yan Date: Thu, 25 Oct 2018 22:21:27 -0700 Subject: [PATCH] fix a race condition. (#212) when multiple call to GetStream happens around the same time, on the same inputIndex, a race condition will cause this.buffers.Add() to throw exception. --- src/KubernetesClient/StreamDemuxer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KubernetesClient/StreamDemuxer.cs b/src/KubernetesClient/StreamDemuxer.cs index 79222fd..e29827f 100644 --- a/src/KubernetesClient/StreamDemuxer.cs +++ b/src/KubernetesClient/StreamDemuxer.cs @@ -98,9 +98,9 @@ namespace k8s /// public Stream GetStream(byte? inputIndex, byte? outputIndex) { - if (inputIndex != null && !this.buffers.ContainsKey(inputIndex.Value)) + lock (this.buffers) { - lock (this.buffers) + if (inputIndex != null && !this.buffers.ContainsKey(inputIndex.Value)) { var buffer = new ByteBuffer(); this.buffers.Add(inputIndex.Value, buffer);