@@ -315,13 +315,9 @@ static void fail_pending_reqs(tlsuv_stream_t *clt, int err) {
315315
316316static void process_outbound (tlsuv_stream_t * clt ) {
317317 tlsuv_write_t * req ;
318- ssize_t ret ;
319-
320- for (;;) {
321- if (TAILQ_EMPTY (& clt -> queue )) {
322- return ;
323- }
318+ ssize_t ret = 0 ;
324319
320+ while (!TAILQ_EMPTY (& clt -> queue )) {
325321 req = TAILQ_FIRST (& clt -> queue );
326322 ret = write_req (clt , & req -> buf );
327323 if (ret > 0 ) {
@@ -336,6 +332,7 @@ static void process_outbound(tlsuv_stream_t *clt) {
336332 req -> wr -> cb (req -> wr , 0 );
337333 }
338334 tlsuv__free (req );
335+ req = NULL ;
339336 }
340337 continue ;
341338 }
@@ -344,15 +341,22 @@ static void process_outbound(tlsuv_stream_t *clt) {
344341 return ;
345342 }
346343
347- UM_LOG (WARN , "failed to write: %d/%s" , (int )ret , uv_strerror (ret ));
348- TAILQ_REMOVE (& clt -> queue , req , _next );
349- clt -> queue_len -= 1 ;
350- if (req -> wr -> cb ) {
351- req -> wr -> cb (req -> wr , (int )ret );
352- }
353344 break ;
354345 }
355346
347+ // write failed so fail all queued requests
348+ if (ret < 0 ) {
349+ UM_LOG (WARN , "failed to write: %d/%s" , (int )ret , uv_strerror (ret ));
350+ while (!TAILQ_EMPTY (& clt -> queue )) {
351+ req = TAILQ_FIRST (& clt -> queue );
352+ TAILQ_REMOVE (& clt -> queue , req , _next );
353+ clt -> queue_len -= 1 ;
354+ if (req -> wr -> cb ) {
355+ req -> wr -> cb (req -> wr , (int ) ret );
356+ }
357+ tlsuv__free (req );
358+ }
359+ }
356360}
357361
358362static void process_inbound (tlsuv_stream_t * clt ) {
0 commit comments