@@ -599,43 +599,44 @@ ngx_http_tnt_send_reply(ngx_http_request_t *r,
599599
600600 rc = tp_transcode (& tc , (char * )ctx -> tp_cache -> start ,
601601 ctx -> tp_cache -> end - ctx -> tp_cache -> start );
602- if (rc == TP_TRANSCODE_OK ) {
602+ if (rc != TP_TRANSCODE_ERROR ) {
603603
604+ /* Finishing
605+ */
604606 size_t complete_msg_size = 0 ;
605607 rc = tp_transcode_complete (& tc , & complete_msg_size );
606608 if (rc == TP_TRANSCODE_ERROR ) {
609+ crit ("[BUG] failed to complete output transcoding. UNKNOWN ERROR" );
610+ goto error_exit ;
611+ }
607612
608- crit ("[BUG] failed to complete output transcoding" );
609-
613+ /* Ok. We send an error to the client from the Tarantool
614+ */
615+ if (rc == TP_TNT_ERROR ) {
610616 ngx_pfree (r -> pool , output );
611617
612- const ngx_http_tnt_error_t * e = get_error_text (UNKNOWN_PARSE_ERROR );
613- output = ngx_http_tnt_set_err (r , e -> code , e -> msg .data , e -> msg .len );
618+ /* Swap output */
619+ output = ngx_http_tnt_set_err (r , tc .errcode ,
620+ (u_char * )tc .errmsg ,
621+ ngx_strlen (tc .errmsg ));
614622 if (output == NULL ) {
615623 goto error_exit ;
616624 }
617-
618- goto done ;
619- }
620-
621- output -> last = output -> pos + complete_msg_size ;
622-
623- } else if (rc == TP_TRANSCODE_ERROR ) {
624-
625- crit ("[BUG] failed to transcode output, err: '%s'" , tc .errmsg );
626-
627- ngx_pfree (r -> pool , output );
628-
629- output = ngx_http_tnt_set_err (r ,
630- tc .errcode ,
631- (u_char * )tc .errmsg ,
632- ngx_strlen (tc .errmsg ));
633- if (output == NULL ) {
634- goto error_exit ;
625+ } else {
626+ output -> last = output -> pos + complete_msg_size ;
635627 }
636628 }
629+ /* Transcoder down
630+ */
631+ else {
632+ crit ("[BUG] failed to transcode output. errcode: '%d', errmsg: '%s'" ,
633+ tc .errcode ,
634+ get_str_safe ((const u_char * )tc .errmsg ));
635+ goto error_exit ;
636+ }
637637
638- done :
638+ /* Transcoding - OK
639+ */
639640 tp_transcode_free (& tc );
640641
641642 if (ctx -> batch_size > 0 ) {
@@ -655,6 +656,9 @@ ngx_http_tnt_send_reply(ngx_http_request_t *r,
655656 return ngx_http_tnt_output (r , u , output );
656657
657658error_exit :
659+ if (output ) {
660+ ngx_pfree (r -> pool , output );
661+ }
658662 tp_transcode_free (& tc );
659663 return NGX_ERROR ;
660664}
0 commit comments