1717
1818import java .io .IOException ;
1919import java .io .InputStream ;
20+ import java .io .OutputStream ;
2021import java .net .HttpURLConnection ;
2122import java .util .Date ;
2223import java .util .Map .Entry ;
@@ -72,6 +73,7 @@ public static <CLIENT_TYPE, PARENT_TYPE, RESULT_TYPE> RESULT_TYPE executeWithRet
7273 int currentRetryCount = 0 ;
7374 StorageException translatedException = null ;
7475 HttpURLConnection request = null ;
76+ OutputStream requestOutputStream = null ;
7577 final long startTime = new Date ().getTime ();
7678
7779 while (true ) {
@@ -87,8 +89,9 @@ public static <CLIENT_TYPE, PARENT_TYPE, RESULT_TYPE> RESULT_TYPE executeWithRet
8789 try {
8890 if (task .getSendStream () != null ) {
8991 Logger .info (opContext , LogConstants .UPLOAD );
92+ requestOutputStream = request .getOutputStream ();
9093 final StreamMd5AndLength descriptor = Utility .writeToOutputStream (task .getSendStream (),
91- request . getOutputStream () , task .getLength (), false /* rewindStream */ ,
94+ requestOutputStream , task .getLength (), false /* rewindStream */ ,
9295 false /* calculate MD5 */ , opContext , task .getRequestOptions ());
9396
9497 task .validateStreamWrite (descriptor );
@@ -131,6 +134,14 @@ public static <CLIENT_TYPE, PARENT_TYPE, RESULT_TYPE> RESULT_TYPE executeWithRet
131134
132135 ExecutionEngine .fireErrorReceivingResponseEvent (opContext , request , task .getResult ());
133136 }
137+ if (requestOutputStream != null ){
138+ if (requestOutputStream != null ) {
139+ try {
140+ requestOutputStream .close ();
141+ } catch (IOException logOrIgnore ) {
142+ }
143+ }
144+ }
134145 }
135146
136147 // 8. Pre-process response to check if there was an exception. Do Response parsing (headers etc).
0 commit comments