Repository navigation
feat(network): handle a busy server with Retry-After (retryAfter/retryCode, gate, reset_retry_after) - #89
Conversation
… Retry-After in sync A CloudSync answer of 429, or 503 with Retry-After, is now a result instead of an SQL error. send_changes, receive_changes and sync return their normal JSON with retryAfter (seconds, 0 without a hint) and retryCode (errors[0].code, or http_<status>) in the refused block. A refused send keeps its checkpoint and is re-sent as a new batch; sync still runs its receive phase after one. The sync receive loop waits a Retry-After instead of wait_ms when it fits the remaining wait_ms * (max_retries - 1) budget, and returns reporting it otherwise, so a call never waits longer than before. A 503 without Retry-After and an HTTP-date Retry-After keep today's behaviour, as does every reply from current servers, which send neither. NETWORK_RESULT gains trailing http_status/has_retry_after/retry_after fields, filled by the libcurl and Apple transports; custom transports that leave them zero keep the previous behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…loudsync_network_reset_retry_after() After a busy refusal, or a /check answered with a delay, send and receive now return the same result with a countdown retryAfter, without contacting the server, until the deadline passes. Send and receive keep separate deadlines, in memory per connection, on the monotonic clock. sync(wait_ms, max_retries) waits out a pending deadline that fits its budget before the first /check. cloudsync_network_reset_retry_after() clears both deadlines, for refreshes the user asked for explicitly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…once Loops written against the previous API.md guidance (send until status leaves out-of-sync, receive while complete is false) would spin at full CPU during a Retry-After wait, and a 429 without Retry-After would resend with no pause. - A busy or held send reports status "syncing" (also covers a busy /status with nothing pending), a busy or held receive reports complete:true. - A 429 without a usable Retry-After waits a default of 5 seconds. - A new cloudsync_network_init() clears the wait; a token refresh keeps it. - A busy refusal whose code cannot be copied sets no wait. - One helper takes the busy fields at the three call sites. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Why a busy result now reports
|
…lly synced Co-Authored-By: Claude Opus 5.5 <[email protected]>
Covered by network_unit: the loop drains a backlog in bounded sends and stops after one call against a busy server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tested: the loop stops after two calls when the server keeps failing a send, and on a WAL database another connection sees each checkpoint commit and can write during the loop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tory (Android has no /tmp) Co-Authored-By: Claude Opus 5.5 <[email protected]>
syncing keeps one meaning (the server holds the changes); busy means the server refused the send and asked to wait retryAfter seconds. Loops that continue only on out-of-sync still stop after one call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Update: a refused send now reports The previous comment explained why a busy or held send reported
🤖 Generated with Claude Code |
Summary
Client side of CloudSync soft-overload handling, compatible with the server changes proposed in sqliteai/cloudsync#94 (S1 delayed
/check, S3 rate limit) and tenant load shedding. Against current servers, which send neither429norRetry-After, behaviour is unchanged.429, or a503carryingRetry-After, on/apply,/upload,/statusor/checkreturns the normal JSON withretryAfter(seconds; 5 when a429carries no usable hint) andretryCode(errors[0].code, orhttp_<status>) in the refusedsend/receiveblock. A503withoutRetry-After(an outage), or with an HTTP-date value, stays an error.status: "busy", a busy or held receive reportscomplete: true, so loops written against the earlier API.md guidance stop after one call (see the comments below).sync()still runs its receive phase after a busy send.sync(wait_ms, max_retries)waits aRetry-Afterinstead ofwait_mswhen it fits the remainingwait_ms × (max_retries − 1)budget, and returns reporting it otherwise. A call never waits longer than before.retryAfterand make no request. Newcloudsync_network_reset_retry_after()lifts it for user-requested refreshes; a newcloudsync_network_init()clears it, a token refresh keeps it.has_unsent_changes()andnetwork_status()stay ungated.NETWORK_RESULTgains trailinghttp_status,has_retry_after,retry_after, filled by libcurl andnetwork.m. Custom transports that leave them zero keep the previous behaviour (docs/internal/network.md).Jitter is requested server-side in https://github.com/sqliteai/cloudsync/issues/94#issuecomment-6294151260. Wrappers need no change: the new fields flow through the SQL JSON. Changelog entries are under
[Unreleased].Test plan
make network-unittest: loopback HTTP server cases for 429/503 with and withoutRetry-After, HTTP-date, busy/upload, mid-batch busy, delayed and busy/check, sync after busy send, budget waits and early return, gated send/receive/sync, pending deadline waited within budget, reset;Retry-Afterparsingout-of-sync, receive while notcomplete) stop after one call against a busy servermake unittestnetwork.mandCLOUDSYNC_OMIT_CURLbuilds compile without warnings locallywindows.h, guarded withWIN32_LEAN_AND_MEAN)🤖 Generated with Claude Code