Skip to content

out_forward: the ACK timeout of an old send rolls back the retry of the same chunk, and the chunk is sent a third time #5679

Backlog

Description

@Watson1978

Describe the bug

With require_ack_response true, the ACK timeout of an old send can roll back a newer send of the same chunk. The chunk is then sent again, although the newer send is still waiting for its ACK.

ack_check calls rollback_write(chunk_id, update_retry: false) when an ACK times out (lib/fluent/plugin/out_forward.rb:549). rollback_write finds the chunk only by its chunk ID (lib/fluent/plugin/output.rb:1178). It cannot tell which send the timeout belongs to. If the chunk was already taken back and sent again, the stale timeout takes back the new send.

This needs the delayed commit timeout to fire before the ACK timeout of the same send. out_forward sets delayed_commit_timeout to ack_response_timeout + 2 to avoid that, but I found two cases on master where it still happens.

  • A send that takes more than about 2 seconds, with default timeouts. The delayed commit clock starts before try_write (lib/fluent/plugin/output.rb:1266). The ACK clock starts after the send (AckHandler#enqueue). So a slow send uses up the 2 second margin.
  • delayed_commit_timeout equal to ack_response_timeout. overwrite_delayed_commit_timeout then keeps both values.

In both cases the delayed commit timeout resends the chunk first. The ACK timeout of the first send fires later and rolls back the second send.

To Reproduce

  1. Save the script below as server.rb. It is a slow destination. It never acknowledges the first copy of a chunk, and acknowledges later copies at once.
  2. Save the configuration below as fluentd.conf.
  3. Run ruby server.rb and fluentd -c fluentd.conf for about 30 seconds.
require 'socket'
require 'msgpack'

seen = Hash.new(0)
lock = Mutex.new
started = Time.now
server = TCPServer.new('127.0.0.1', 24412)
$stdout.sync = true
loop do
  Thread.new(server.accept) do |sock|
    unpacker = MessagePack::Unpacker.new
    begin
      loop do
        unpacker.feed_each(sock.readpartial(65536)) do |_tag, _entries, option|
          chunk = option['chunk']
          count = lock.synchronize { seen[chunk] += 1 }
          puts format('%6.2fs chunk=%s copy=%d', Time.now - started, chunk.strip[0, 8], count)
          sock.write({ 'ack' => chunk }.to_msgpack) if count > 1
        end
      end
    rescue EOFError, SystemCallError
    ensure
      sock.close
    end
  end
end

Some chunks arrive three times. The third copy arrives about one second after the second one.

  1.95s chunk=ZhEDNn// copy=1
  5.96s chunk=ZhEDNn// copy=2
  6.87s chunk=ZhEDNn// copy=3

In a 30 second run, 3 of 25 chunks arrived three times. It does not happen for every chunk, because the ACK of the second send often arrives before the stale timeout is processed.

Without the delayed_commit_timeout 3s line, no chunk arrived more than twice (33 chunks).

With the default heartbeat_type transport (remove the heartbeat_type none line), it still happens, but less often (1 of 32 chunks).

The slow send case does not need the delayed_commit_timeout line. I used 8 MB chunks and a destination that starts reading 3 seconds after it accepts a connection. In a 40 second run, 2 of 8 chunks arrived three times (1 of 8 with heartbeat_type transport). When the destination reads at once, no chunk arrived more than twice (23 chunks). The changes to the files above:

 # server.rb
 server = TCPServer.new('127.0.0.1', 24412)
+server.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, 65536)
 ...
     begin
+      sleep 3
       loop do
 # fluentd.conf
   rate 1
-  size 1
+  size 8
+  sample "#{ JSON.generate('m' => 'x' * 1_000_000) }"
 ...
     flush_mode immediate
-    delayed_commit_timeout 3s
+    chunk_limit_size 64m

Expected behavior

Each chunk arrives twice here. The first copy gets no ACK, so one resend is correct. The timeout of the first send should not roll back the second send.

Your Environment

- Fluentd version: 1.20.1 (master at 04093935)
- Package version: none (git checkout)
- Operating system: CachyOS
- Kernel version: 7.3.5-2-cachyos
- Ruby: 4.0.10

Your Configuration

<source>
  @type sample
  tag test
  rate 1
  size 1
</source>

<match test>
  @type forward
  require_ack_response true
  ack_response_timeout 3s
  heartbeat_type none
  <server>
    host 127.0.0.1
    port 24412
  </server>
  <buffer>
    flush_mode immediate
    delayed_commit_timeout 3s
  </buffer>
</match>

Your Error Log

2026-11-25 11:01:13 +0900 [warn]: #0 failed to flush the buffer chunk, timeout to commit. chunk_id="661103367fff202c57052c9d56d5be9a" flushed_at=2026-11-25 11:01:10.089225692 +0900
2026-11-25 11:01:13 +0900 [warn]: #0 no response from node. regard it as unavailable. host="127.0.0.1" port=24412
2026-11-25 11:01:14 +0900 [warn]: #0 retry succeeded. chunk_id="661103367fff202c57052c9d56d5be9a"

Additional context

There is one more case after the fix for #5633 (#5636 or #5651). Then a rollback_write from an out_forward secondary reaches the primary. The primary's delayed_commit_timeout (60 seconds by default) is shorter than the secondary's ack_response_timeout (190 seconds by default), so the same order happens with default settings. This was seen in the reviews of #5636 and #5651.

A fix needs to carry which send an ACK belongs to, from the ACK handler to rollback_write. That touches the same lines as #5673 and #5675 (ack_check and the ACK waiting info) and as #5636 and #5651 (the secondary's rollback_write). So it is better to start the fix after #5673 and #5675 are merged and after it is decided which of #5636 and #5651 is taken.

Activity

  1. added
    bug
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions