Skip to content

Bound the empty-read retry in read_complete - #1296

Closed
Pranav-error wants to merge 1 commit into
pgmoneta:mainfrom
Pranav-error:bound-eagain-retry
Closed

Pranav-error wants to merge 1 commit into
pgmoneta:mainfrom
Pranav-error:bound-eagain-retry

Conversation

@Pranav-error

Copy link
Copy Markdown
Collaborator

Draft, as you suggested on #1295. The change is small; the number in it is the part worth arguing about.

read_complete() bounds one retry path but not the other. A short read sleeps 10ms and gives up after 100 tries. EAGAIN retried immediately, forever, with no counter and no sleep:

if (errno == EAGAIN || errno == EWOULDBLOCK)
{
   errno = 0;
   goto read;
}

Against a connected but silent peer that is 5.4 million read() calls in 2 seconds, spinning a core until something else kills the process:

peer connected but silent, reading 1 byte:

  OLD: STILL SPINNING, cut off  -- 5442515 read() calls in 2.0s (busy spin, no sleep)
  NEW: returned 1 (ETIMEDOUT) after 20 retries in 0.29s

(The harness uses a scaled-down bound so it finishes quickly; the real one is 30000.)

The number is the question

read_complete() reads the response header, and that header only arrives once the command has finished — so a backup can legitimately keep the caller waiting for minutes. Any bound here is therefore also a cap on how long a management command may take before the client gives up on it.

I picked 30000 x 10ms = five minutes as something clear of a slow command but still finite, and put it in management.h as MANAGEMENT_READ_EMPTY_RETRIES rather than burying a literal. I do not know your real upper bound for a backup on a large cluster, so this may be too low, and a per-command budget may be the better shape.

Three ways this could go, whichever you prefer:

  1. Keep the bound, change the number — tell me what a backup can realistically take and I will set it.
  2. Sleep but do not bound. This still fixes the CPU burn, which is unambiguous, and leaves the wait unbounded exactly as today. It would not fix a hang.
  3. Wait on the descriptor instead of polling it — poll() on the socket rather than retrying read(). No arbitrary deadline and no spin, but a larger change to a shared path.

On whether this is the CI hang

I do not claim it is. As I said on #1295, I have no stack trace from a hung runner and cannot reproduce the timeout locally. This is a real defect on its own — a busy loop with no exit — and fixing it is worthwhile regardless of what the CI turns out to be doing.

Verification

Builds clean, clang-format quiet, json module passes 6/6. The cli module segfaults here both with and without this change, because it needs a live server that the CI containers provide and I do not have locally — so it is not evidence either way.

@jesperpedersen

Copy link
Copy Markdown
Member

Please, rebase

read_complete() bounded one retry path but not the other. A short read
sleeps 10ms and gives up after 100 tries; EAGAIN retried immediately,
forever, with no counter and no sleep. The asymmetry looks unintended.

Against a connected but silent peer the old path issues 5.4 million
read() calls in 2 seconds and never returns, so a caller waiting on a
management response spins a core until something else kills it.

This sleeps 10ms before retrying, which is what the short-read path
already does, and gives up after MANAGEMENT_READ_EMPTY_RETRIES with
ETIMEDOUT.

The bound is the part worth arguing about, so it is a named constant
rather than a literal. read_complete() reads the response header, and
that header only arrives once the command has finished, so a backup can
legitimately keep the caller waiting for minutes. 30000 x 10ms is five
minutes, which is meant to be well clear of a slow command while still
being finite. A different number, or a per-command budget, may be the
better answer.

Verified with a harness that runs both versions against a non-blocking
socket whose peer never writes. Not verified against a real hung
management command.

Signed-off-by: sai pranav <[email protected]>
@jesperpedersen

Copy link
Copy Markdown
Member

Rebased and merged.

Thanks for your contribution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants