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

@@ -98,9 +98,9 @@ namespace k8s
/// </returns> /// </returns>
public Stream GetStream(byte? inputIndex, byte? outputIndex) 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(); var buffer = new ByteBuffer();
this.buffers.Add(inputIndex.Value, buffer); this.buffers.Add(inputIndex.Value, buffer);