'db:connection-closed' error when retrying writes in Racket's db library
0 reputation · 07 May 2022, 16:38 UTC
The Racket db library throws a 'db:connection-closed' exception when a connection is lost during a transaction. The documentation does not specify how retrying such a write should be handled, leaving the developer to decide whether to re‑execute the statement. Re‑execution can result in duplicate rows because the library provides no built‑in duplicate‑write detection or idempotency tracking. Meanwhile, the http client offers a retry keyword for GET requests but not for POST or other state‑changing methods, creating a similar asymmetry for HTTP writes.
Given this gap, should Racket introduce a higher‑level abstraction that safely retries write operations without risking duplication? 1) How might such an abstraction detect whether a write has already been applied after a failure? 2) Could unique constraints or operation IDs be leveraged to enforce idempotency? 3) What trade‑offs would arise from adding automatic retry logic to the db and http libraries?