10
10
using System . Diagnostics ;
11
11
using Microsoft . VisualStudio . Services . WebApi ;
12
12
using System . Net . Http ;
13
+ using System . Net ;
13
14
14
15
namespace Microsoft . VisualStudio . Services . Agent . Worker . Build
15
16
{
@@ -183,8 +184,6 @@ private async Task<List<string>> UploadAsync(IAsyncCommandContext context, int u
183
184
while ( _fileUploadQueue . TryDequeue ( out fileToUpload ) )
184
185
{
185
186
token . ThrowIfCancellationRequested ( ) ;
186
- Interlocked . Increment ( ref _filesProcessed ) ;
187
-
188
187
using ( FileStream fs = File . Open ( fileToUpload , FileMode . Open , FileAccess . Read ) )
189
188
{
190
189
string itemPath = ( _containerPath . TrimEnd ( '/' ) + "/" + fileToUpload . Remove ( 0 , _sourceParentDirectory . Length + 1 ) ) . Replace ( '\\ ' , '/' ) ;
@@ -198,6 +197,12 @@ private async Task<List<string>> UploadAsync(IAsyncCommandContext context, int u
198
197
catch ( OperationCanceledException ) when ( token . IsCancellationRequested )
199
198
{
200
199
context . Output ( StringUtil . Loc ( "FileUploadCancelled" , fileToUpload ) ) ;
200
+ if ( response != null )
201
+ {
202
+ response . Dispose ( ) ;
203
+ response = null ;
204
+ }
205
+
201
206
throw ;
202
207
}
203
208
catch ( Exception ex )
@@ -208,7 +213,7 @@ private async Task<List<string>> UploadAsync(IAsyncCommandContext context, int u
208
213
}
209
214
210
215
uploadTimer . Stop ( ) ;
211
- if ( catchExceptionDuringUpload || response . StatusCode != System . Net . HttpStatusCode . Created )
216
+ if ( catchExceptionDuringUpload || ( response != null && response . StatusCode != HttpStatusCode . Created ) )
212
217
{
213
218
if ( response != null )
214
219
{
@@ -246,7 +251,15 @@ private async Task<List<string>> UploadAsync(IAsyncCommandContext context, int u
246
251
}
247
252
}
248
253
}
254
+
255
+ if ( response != null )
256
+ {
257
+ response . Dispose ( ) ;
258
+ response = null ;
259
+ }
249
260
}
261
+
262
+ Interlocked . Increment ( ref _filesProcessed ) ;
250
263
}
251
264
252
265
return failedFiles ;
0 commit comments