Unable to download package: The file <filename> already exists

I’m running into a strange issue. For one specific package (all others download fine), I get the error "Unable to download package: The file already exists."
I can see the package in Artifactory and download it to my machine from Artifactory. I’ve tried changing the package in the release to older versions that I know worked in the past, but I get the same error. Interestingly, when I do a deployment to some other environments (in different physical locations, using different artifactory servers), the package downloads fine.
When I look on the server under D:\Octopus\files<feed name>\ I can see a 0KB version of the file listed above (should be 6KB). Deleting it does not resolve the issue.
Any ideas on how I can further troubleshoot this?

Task ID:        ServerTasks-35448
Task status:    Canceled
Task queued:    28. september 2016 00:16
Task started:   28. september 2016 00:16
Task duration:  38 seconds
Server version: 3.4.8+Branch.master.Sha.3b954a4f3454a6e57742a7a5d5d9e2708a12f454
                    | == Failed: Deploy ActionManagement release 19.1.35.389 to euro.confirmit.com ==
00:16:59   Info     |   Step 1: Download Package and Execute DB Step Files was manually skipped, and will not be executed
00:16:59   Info     |   Step 3: Set IIS log path and log fields (and create log folder if needed) was manually skipped, and will not be executed
00:16:59   Info     |   Step 4: DeployFiltersViewModelAPIWebApp was manually skipped, and will not be executed
00:16:59   Info     |   Step 5: DeployActionManagementPackage was manually skipped, and will not be executed
00:16:59   Info     |   Step 6: DeployCaseEmailService was manually skipped, and will not be executed
00:16:59   Info     |   Step 7: DeployHubSyncService was manually skipped, and will not be executed
00:16:59   Info     |   Step 8: DeployTriggerService was manually skipped, and will not be executed
00:16:59   Info     |   Step 9: DeployCaseMigrationService was manually skipped, and will not be executed
00:16:59   Info     |   Step 10: Start Back End services IF they are set to Automatic was manually skipped, and will not be executed
00:16:59   Verbose  |   Guided failure is enabled for this task
00:17:37   Info     |   Requesting cancellation...
00:17:37   Fatal    |   The deployment failed because one or more steps failed. Please see the deployment log for details.
                    |   == Failed: Acquire packages ==
00:16:59   Info     |     Acquiring packages
00:16:59   Info     |     Making a list of packages to download
00:17:37   Fatal    |     The step failed: The operation was canceled.
00:17:37   Verbose  |     Acquire Packages completed
                    |     Warning: LN3AMC01-2012R2
00:17:12   Error    |       The remote script failed with exit code 100
00:17:39   Info     |       This task has been canceled.
                    |       Running: Download package Confirmit.Nxlog version 1.0.13 from http://10.103.22.143/artifactory/api/nuget/nuget-confimit-SF-saas-virtual
00:17:02   Verbose  |         Octopus Deploy: Calamari version 3.4.17+Branch.master.Sha.e4e64505148ba31628ece4adf522af1f6f85a9c1
00:17:02   Verbose  |         Name                           Value
00:17:02   Verbose  |         ----                           -----
00:17:02   Verbose  |         PSVersion                      4.0
00:17:02   Verbose  |         WSManStackVersion              3.0
00:17:02   Verbose  |         SerializationVersion           1.1.0.1
00:17:02   Verbose  |         CLRVersion                     4.0.30319.34209
00:17:02   Verbose  |         BuildVersion                   6.3.9600.17400
00:17:02   Verbose  |         PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
00:17:02   Verbose  |         PSRemotingProtocolVersion      2.2
00:17:02   Verbose  |         Octopus Deploy: Calamari version 3.4.17+Branch.master.Sha.e4e64505148ba31628ece4adf522af1f6f85a9c1
00:17:02   Info     |         Downloading NuGet package Confirmit.Nxlog 1.0.13 from feed: 'http://10.103.22.143/artifactory/api/nuget/nuget-confimit-SF-saas-virtual'
00:17:02   Verbose  |         Downloaded package will be stored in: 'D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro'
00:17:02   Verbose  |         Downloading package (attempt 1 of 3)
00:17:03   Verbose  |         Found package Confirmit.Nxlog version 1.0.13
00:17:03   Verbose  |         Downloading to: D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg
00:17:03   Verbose  |         A direct download is possible; bypassing the NuGet machine cache
00:17:06   Verbose  |         Attempt 1 of 3: Unable to download package: System.Net.WebException: The remote server returned an error: (404) Not Found.
00:17:06   Verbose  |         at System.Net.HttpWebRequest.GetResponse()
00:17:06   Verbose  |         at NuGet.RequestHelper.GetResponse()
00:17:06   Verbose  |         at NuGet.HttpClient.DownloadData(Stream targetStream)
00:17:06   Verbose  |         at NuGet.PackageDownloader.DownloadPackage(IHttpClient downloadClient, IPackageName package, Stream targetStream)
00:17:06   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetV2Downloader.DownloadPackage(IPackage package, String fullPathToDownloadTo, PackageDownloader directDownloader) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetV2Downloader.cs:line 53
00:17:06   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetPackageDownloader.DownloadPackage(String packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, String targetFilePath) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetPackageDownloader.cs:line 41
00:17:07   Verbose  |         Downloading package (attempt 2 of 3)
00:17:08   Verbose  |         Found package Confirmit.Nxlog version 1.0.13
00:17:08   Verbose  |         Downloading to: D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg
00:17:08   Verbose  |         A direct download is possible; bypassing the NuGet machine cache
00:17:08   Verbose  |         Attempt 2 of 3: Unable to download package: System.IO.IOException: The file 'D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg' already exists.
00:17:08   Verbose  |         at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
00:17:08   Verbose  |         at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
00:17:08   Verbose  |         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
00:17:08   Verbose  |         at System.IO.FileStream..ctor(String path, FileMode mode)
00:17:08   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetV2Downloader.DownloadPackage(IPackage package, String fullPathToDownloadTo, PackageDownloader directDownloader) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetV2Downloader.cs:line 52
00:17:08   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetPackageDownloader.DownloadPackage(String packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, String targetFilePath) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetPackageDownloader.cs:line 41
00:17:09   Verbose  |         Downloading package (attempt 3 of 3)
00:17:10   Verbose  |         Found package Confirmit.Nxlog version 1.0.13
00:17:10   Verbose  |         Downloading to: D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg
00:17:10   Verbose  |         A direct download is possible; bypassing the NuGet machine cache
00:17:10   Verbose  |         Attempt 3 of 3: Unable to download package: System.IO.IOException: The file 'D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg' already exists.
00:17:10   Verbose  |         at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
00:17:10   Verbose  |         at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
00:17:10   Verbose  |         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
00:17:10   Verbose  |         at System.IO.FileStream..ctor(String path, FileMode mode)
00:17:10   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetV2Downloader.DownloadPackage(IPackage package, String fullPathToDownloadTo, PackageDownloader directDownloader) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetV2Downloader.cs:line 52
00:17:10   Verbose  |         at Calamari.Integration.Packages.NuGet.NuGetPackageDownloader.DownloadPackage(String packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, String targetFilePath) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetPackageDownloader.cs:line 41
00:17:11   Verbose  |         Downloading package (attempt 4 of 3)
00:17:12   Verbose  |         Found package Confirmit.Nxlog version 1.0.13
00:17:12   Verbose  |         Downloading to: D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg
00:17:12   Verbose  |         A direct download is possible; bypassing the NuGet machine cache
00:17:12   Error    |         Unable to download package: The file 'D:\Octopus\Files\feeds-nuget-confirmit-sf-saas-euro\Confirmit.Nxlog.1.0.13_12AB6A64D9C8114C8A7F079BDDB122FD.nupkg' already exists.
00:17:12   Error    |         Failed to download package Confirmit.Nxlog 1.0.13 from feed: 'http://10.103.22.143/artifactory/api/nuget/nuget-confimit-SF-saas-virtual'
00:17:12   Error    |         System.Exception: The package could not be downloaded from NuGet. If you are getting a package verification error, try switching to a Windows File Share package repository to see if that helps.
00:17:12   Error    |         at Calamari.Integration.Packages.NuGet.NuGetPackageDownloader.DownloadPackage(String packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, String targetFilePath) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\NuGet\NuGetPackageDownloader.cs:line 58
00:17:12   Error    |         at Calamari.Integration.Packages.Download.PackageDownloader.DownloadPackage(String packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, String cacheDirectory, LocalNuGetPackage& downloaded, String& downloadedTo) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\Download\PackageDownloader.cs:line 126
00:17:12   Error    |         at Calamari.Integration.Packages.Download.PackageDownloader.DownloadPackage(String packageId, NuGetVersion version, String feedId, Uri feedUri, ICredentials feedCredentials, Boolean forcePackageDownload, String& downloadedTo, String& hash, Int64& size) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Integration\Packages\Download\PackageDownloader.cs:line 47
00:17:12   Error    |         at Calamari.Commands.DownloadPackageCommand.Execute(String[] commandLineArguments) in Z:\BuildAgent\work\14ffc968155e4956\source\Calamari\Commands\DownloadPackageCommand.cs:line 57
                    |   Canceled: Step 2: Confirmit.Nxlog
00:17:37   Verbose  |     Step "Confirmit.Nxlog" runs only when all previous steps succeeded; skipping

Hi Peter,

Thanks for reaching out! Sorry about my delay in responding to your question. After looking in to it, it looks like the failed package download is being caused by a bug. The first attempt to download the package is creating the file on disk, but isn’t writing the data in to it. When it retries, it sees the file and fails with the error. We’ve created a GitHub issue to work on resolving this.

Kind regards,

Kenny