Skip to content

Commit e17f61e

Browse files
zshuang0316claude
andcommitted
out_forward: close connection on failed flush to avoid frame desync
A forward frame is written as multiple non-atomic writes (header, body, options). When one of them fails, part of the frame may already be on the socket, so returning the connection to the keepalive pool lets the next frame be read as the truncated frame's missing piece and desyncs the receiver's msgpack stream. Force the connection closed on error so the next flush starts on a fresh connection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: zshuang0316 <zshuang0316@163.com>
1 parent a1e05fc commit e17f61e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

plugins/out_forward/forward.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@ static void cb_forward_flush(struct flb_event_chunk *event_chunk,
17891789
flb_plg_debug(ctx->ins, "handshake status = %i", ret);
17901790
if (ret == -1) {
17911791
if (u_conn) {
1792+
flb_upstream_conn_recycle(u_conn, FLB_FALSE);
17921793
flb_upstream_conn_release(u_conn);
17931794
}
17941795

@@ -1833,6 +1834,17 @@ static void cb_forward_flush(struct flb_event_chunk *event_chunk,
18331834
}
18341835

18351836
if (u_conn) {
1837+
if (ret != FLB_OK) {
1838+
/*
1839+
* A forward frame is written as multiple non-atomic writes
1840+
* (header, body, options). On failure part of it may already be
1841+
* on the socket, so don't return the connection to the keepalive
1842+
* pool: the next frame would be read as the truncated frame's
1843+
* missing piece and desync the receiver's msgpack stream. Force
1844+
* it closed so the next flush starts on a fresh connection.
1845+
*/
1846+
flb_upstream_conn_recycle(u_conn, FLB_FALSE);
1847+
}
18361848
flb_upstream_conn_release(u_conn);
18371849
}
18381850

0 commit comments

Comments
 (0)