Fix replica auth and idempotency races

This commit is contained in:
Tmribob
2026-11-06 16:13:24 +03:00
parent 57c81ea9d5
commit 057877d299
22 changed files with 682 additions and 60 deletions
+31
View File
@@ -0,0 +1,31 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Used only by scripts/research-scale.py with compose.scale.yaml.
upstream api {
server api-1:8080 max_fails=3 fail_timeout=10s;
server api-2:8080 max_fails=3 fail_timeout=10s;
server api-3:8080 max_fails=3 fail_timeout=10s;
server api-4:8080 max_fails=3 fail_timeout=10s;
}
server {
listen 8080;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 2s;
proxy_read_timeout 10s;
proxy_send_timeout 10s;
proxy_next_upstream error timeout http_502;
proxy_next_upstream_tries 4;
location / { proxy_pass http://api; }
}
}
+9 -3
View File
@@ -28,9 +28,15 @@ http {
proxy_read_timeout 10s;
proxy_send_timeout 10s;
# Redirect on 502/503 to the next available replica once, then give up.
proxy_next_upstream error timeout http_502 http_503;
proxy_next_upstream_tries 1;
# A refused connection/502 means the selected replica is unavailable and
# can be retried on its peer. A structured 503 is an application
# dependency failure (for example PostgreSQL down), not an unhealthy
# replica: propagating it preserves the API error envelope instead of
# marking both live peers down and manufacturing an Nginx 502.
proxy_next_upstream error timeout http_502;
# Two attempts cover both configured replicas: a request that lands on
# the stopped instance is retried once on its healthy peer.
proxy_next_upstream_tries 2;
location / {
proxy_pass http://api;