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

Commit

Permalink
Merge pull request #2534 from khellang/prevent-deadlock
Browse files Browse the repository at this point in the history
Remove Wait call to prevent deadlock
  • Loading branch information
thecodejunkie authored Aug 30, 2016
2 parents 36b1396 + 0cf8c58 commit ea703b8
Showing 1 changed file with 4 additions and 14 deletions.
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

0 comments on commit ea703b8

Please sign in to comment.