How to resolve NuGet Push failures after 5 minutes, even though “-Timeout” value is set as greater than 5 minutes (300 seconds)

ISSUE:

If you see NuGet push failing with the following error, it could be due to a known issue by NuGet.

./nuget push largefiletest.1.0.1.nupkg -Source Artifactory3 -Timeout 2400 -Verbosity detailed


Pushing largefiletest 1.0.1 to ‘https://dropbox.artifactoryonline.com/dropbox/api/nuget/nugettest‘…

PUT https://dropbox.artifactoryonline.com/dropbox/api/nuget/nugettest/

System.Net.WebException: The request was aborted: The request was canceled. —> System.IO.IOException: Cannot close str

eam until all bytes are written.

   at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)

   — End of inner exception stack trace —

   at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)

   at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)

   at System.Net.ConnectStream.Dispose(Boolean disposing)

   at System.IO.Stream.Close()

   at System.IO.Stream.Dispose()

   at NuGet.MultipartWebRequest.CreateMultipartRequest(WebRequest request)

   at NuGet.PackageServer.<>c__DisplayClass4.<PushPackageToServer>b__2(Object sender, WebRequestEventArgs e)

   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)

   at NuGet.HttpClient.RaiseSendingRequest(WebRequest webRequest)

   at NuGet.RequestHelper.GetResponse()

   at NuGet.HttpClient.GetResponse()

   at NuGet.PackageServer.EnsureSuccessfulResponse(HttpClient client, Nullable`1 expectedStatusCode)

   at NuGet.PackageServer.PushPackageToServer(String apiKey, Func`1 packageStreamFactory, Int64 packageSize, Int32 timeo

ut, Boolean disableBuffering)

   at NuGet.PackageServer.PushPackage(String apiKey, IPackage package, Int64 packageSize, Int32 timeout, Boolean disable

Buffering)

   at NuGet.Commands.PushCommand.PushPackageCore(String source, String apiKey, PackageServer packageServer, String packa

geToPush, TimeSpan timeout)

   at NuGet.Commands.PushCommand.PushPackage(String packagePath, String source, String apiKey, TimeSpan timeout)

   at NuGet.Commands.PushCommand.ExecuteCommand()

   at NuGet.Commands.Command.Execute()

   at NuGet.Program.Main(String[] args) 

The error is received because the nuget client is ignoring the “Timeout” value put in. We found that this has been reported to the NuGet team https://nuget.codeplex.com/SourceControl/network/forks/styx31/nuget/contribution/5969 .

RESOLUTION

As a work-around, please set the NuGet timeout value to one that is NOT DIVISIBLE BY 60. For example,  ./nuget push largefiletest.1.0.1.nupkg -Source Artifactory2 –Timeout 2401 -Verbosity detailed