File tree Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -385,10 +385,24 @@ where
385385 }
386386
387387 fn poll_flush ( & mut self , cx : & mut Context < ' _ > ) -> Poll < crate :: Result < ( ) > > {
388- self . conn . poll_flush ( cx) . map_err ( |err| {
389- debug ! ( "error writing: {}" , err) ;
390- crate :: Error :: new_body_write ( err)
391- } )
388+ if let Poll :: Ready ( res) = self . conn . poll_flush ( cx) {
389+ return Poll :: Ready ( res. map_err ( |err| {
390+ debug ! ( "error writing: {}" , err) ;
391+ crate :: Error :: new_body_write ( err)
392+ } ) ) ;
393+ }
394+
395+ // Drop the body_rx if it's done.
396+ if let ( Some ( body) , clear_body) =
397+ OptGuard :: new ( self . body_rx . as_mut ( ) ) . guard_mut ( )
398+ {
399+ if let Poll :: Ready ( Err ( e) ) = body. poll_progress ( cx) {
400+ * clear_body = true ;
401+ return Poll :: Ready ( Err ( crate :: Error :: new_user_body ( e) ) ) ;
402+ }
403+ }
404+
405+ Poll :: Pending
392406 }
393407
394408 fn close ( & mut self ) {
Original file line number Diff line number Diff line change @@ -128,20 +128,30 @@ where
128128
129129 if me. body_tx . capacity ( ) == 0 {
130130 loop {
131- match ready ! ( me. body_tx. poll_capacity( cx) ) {
132- Some ( Ok ( 0 ) ) => { }
133- Some ( Ok ( _) ) => break ,
134- Some ( Err ( e) ) => {
131+ match me. body_tx . poll_capacity ( cx) {
132+ Poll :: Ready ( Some ( Ok ( 0 ) ) ) => continue ,
133+ Poll :: Ready ( Some ( Ok ( _) ) ) => break ,
134+ Poll :: Ready ( Some ( Err ( e) ) ) => {
135135 return Poll :: Ready ( Err ( crate :: Error :: new_body_write ( e) ) )
136136 }
137- None => {
137+ Poll :: Ready ( None ) => {
138138 // None means the stream is no longer in a
139139 // streaming state, we either finished it
140140 // somehow, or the remote reset us.
141141 return Poll :: Ready ( Err ( crate :: Error :: new_body_write (
142142 "send stream capacity unexpectedly closed" ,
143143 ) ) ) ;
144144 }
145+ Poll :: Pending => {
146+ // If we're waiting for capacity, poll the body stream
147+ // to see if it's been canceled.
148+ return match me. stream . as_mut ( ) . poll_progress ( cx) {
149+ Poll :: Ready ( Err ( e) ) => {
150+ Poll :: Ready ( Err ( me. body_tx . on_user_err ( e) ) )
151+ }
152+ _ => Poll :: Pending ,
153+ } ;
154+ }
145155 }
146156 }
147157 } else if let Poll :: Ready ( reason) = me
You can’t perform that action at this time.
0 commit comments