diff --git a/plugins/out_tcp/tcp.c b/plugins/out_tcp/tcp.c index 1eb77052245..b4a6c0868b8 100644 --- a/plugins/out_tcp/tcp.c +++ b/plugins/out_tcp/tcp.c @@ -94,12 +94,6 @@ static void cb_tcp_flush(struct flb_event_chunk *event_chunk, size_t out_size = 0; (void) i_ins; - ret = compose_payload(ctx, event_chunk->data, event_chunk->size, - &out_payload, &out_size); - if (ret != FLB_OK) { - return FLB_OUTPUT_RETURN(ret); - } - /* Get upstream context and connection */ u = ctx->u; u_conn = flb_upstream_conn_get(u); @@ -109,6 +103,13 @@ static void cb_tcp_flush(struct flb_event_chunk *event_chunk, FLB_OUTPUT_RETURN(FLB_RETRY); } + ret = compose_payload(ctx, event_chunk->data, event_chunk->size, + &out_payload, &out_size); + if (ret != FLB_OK) { + flb_upstream_conn_release(u_conn); + return FLB_OUTPUT_RETURN(ret); + } + if (ctx->out_format == FLB_PACK_JSON_FORMAT_NONE) { ret = flb_io_net_write(u_conn, event_chunk->data, event_chunk->size,