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.
This commit is contained in:
Xin Yan
2018-10-25 22:21:27 -07:00
committed by Brendan Burns
parent 99dc2f7aaf
commit 25523d1985

View File

@@ -97,10 +97,10 @@ namespace k8s
/// A <see cref="Stream"/> which allows you to read/write to the requested channels.
/// </returns>
public Stream GetStream(byte? inputIndex, byte? outputIndex)
{
if (inputIndex != null && !this.buffers.ContainsKey(inputIndex.Value))
{
lock (this.buffers)
{
if (inputIndex != null && !this.buffers.ContainsKey(inputIndex.Value))
{
var buffer = new ByteBuffer();
this.buffers.Add(inputIndex.Value, buffer);