Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Remove Wait call to prevent deadlock #2534

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/Nancy/IO/RequestStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
{
using System;
using System.IO;
using System.Threading.Tasks;

using Nancy.Extensions;

/// <summary>
/// A <see cref="Stream"/> decorator that can handle moving the stream out from memory and on to disk when the contents reaches a certain length.
Expand Down Expand Up @@ -74,15 +71,7 @@ public RequestStream(Stream stream, long expectedLength, long thresholdLength, b

if (!this.stream.CanSeek)
{
var task =
MoveToWritableStream();

task.Wait();

if (task.IsFaulted)
{
throw new InvalidOperationException("Unable to copy stream", task.Exception);
}
this.MoveToWritableStream();
}

this.stream.Position = 0;
Expand All @@ -93,12 +82,13 @@ public RequestStream(Stream stream, long expectedLength, long thresholdLength, b
this.Dispose(false);
}

private Task MoveToWritableStream()
private void MoveToWritableStream()
{
var sourceStream = this.stream;

this.stream = new MemoryStream(BufferSize);

return sourceStream.CopyToAsync(this);
sourceStream.CopyTo(this.stream);
}

/// <summary>
Expand Down