1 Commits

Author SHA1 Message Date
ncantu
37446c8483 Fix: Increase anchor API timeout and improve error handling
**Motivations:**
- Anchor API requests were timing out with "This operation was aborted" errors
- Multiple simultaneous anchor requests can wait for mutex, causing delays
- Slow Bitcoin RPC calls can exceed the 120s timeout

**Root causes:**
- Timeout of 120s was too short when multiple anchors are in progress (mutex wait)
- Slow Bitcoin RPC operations (listunspent, createrawtransaction, sign, send) can take longer than 120s
- Insufficient logging made it difficult to diagnose timeout vs connection closure

**Correctifs:**
- Increased ANCHOR_API_TIMEOUT_MS from 120000 (120s) to 180000 (180s) to handle mutex waits and slow RPC calls
- Added start time tracking to measure elapsed time for all operations
- Enhanced logging with:
  - Log at request start with url, documentUid, hash (truncated), timeoutMs
  - Log on success with txid and elapsedMs
  - Log on abort with elapsedMs, timeoutMs, errorName, errorCode
  - Log on failure with elapsedMs, errorName, errorCode
- Improved error message to include elapsed time: "timeout or connection closed after Xs"
- Added timeout-specific log when timeout is reached (before abort)

**Evolutions:**
- Better observability with elapsed time in all logs
- More detailed error information (errorName, errorCode) for diagnosis
- Timeout log helps distinguish timeout from early connection closure

**Pages affectées:**
- api-filigrane/src/routes/watermark.js: Increased timeout, added timing and enhanced logging
- fixKnowledge/api-filigrane-anchor-request-aborted.md: Updated documentation with new timeout (180s), improved logging details, and mutex wait explanation
2026-01-28 11:29:58 +01:00