Исправить замечания ревью: битый JPEG, память nginx, 502 вместо 413

JPEG проверяется через djpeg -strict: обрезанный поток с дописанным EOI
теперь даёт 415. Память nginx больше не зависит от тел файлов: загрузка
идёт потоком до API, скачивание без временных файлов, воркеров 2. API не
закрывает соединение при недочитанном теле, что давало HTML 502; nginx
сам отклоняет тела больше лимитов API. Лимит памяти API поднят до 512 MiB
под проверку CMYK-JPEG на 40 Мпикс. Добавлен стресс-тест через LB.
This commit is contained in:
alenchha
2026-11-05 13:53:08 +03:00
parent 2152d0dcad
commit a856128b45
19 changed files with 470 additions and 86 deletions
+7
View File
@@ -1,2 +1,9 @@
ok auth and membership on upload
ok file over 10 MiB -> 413
ok 48 Mpx image -> 413 before decoding
ok corrupted image -> 415
ok MIME spoofing and unsupported types -> 415
ok dangerous filenames -> 400
ok unknown / foreign / other-chat attachment ids rejected, no 500
ok client abort mid-upload sent; server must stay healthy
PASS: attachment negative scenarios
+1 -1
View File
@@ -1,2 +1,2 @@
{"observed_instances_before": 2, "successful_writes": 131, "failed_attempts": 0, "first_recovery_seconds": 0.447}
{"observed_instances_before": 2, "successful_writes": 131, "failed_attempts": 0, "first_recovery_seconds": 0.441}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+1
View File
@@ -1,4 +1,5 @@
ok truncated PNG, bad filter byte, broken IDAT, 27-byte JPEG stub -> 415
ok real JPEG accepted; first half + EOI and first half alone -> 415
ok same defects in images above the full-decode threshold (6 Mpx) -> 415
ok valid 6 Mpx PNG accepted
ok valid 36 Mpx PNG (116 KiB on the wire, 108 MiB decoded) accepted in 0.1s
+19 -5
View File
@@ -1,5 +1,19 @@
valid 3000x2000 baseline accepted 0.08s ok
valid 3000x2000 progressive accepted 0.14s ok
27-byte stub rejected 415 0.00s ok
scan cut in half, no EOI rejected 415 0.00s ok
headers only + EOI rejected 415 0.01s ok
valid baseline 675893 bytes accepted 0.01s ok
valid progressive 616591 bytes accepted 0.02s ok
valid grayscale 359415 bytes accepted 0.00s ok
valid CMYK 1262509 bytes accepted 0.01s ok
valid, junk after EOI 675901 bytes accepted 0.01s ok
valid 40 Mpx baseline 626630 bytes accepted 0.01s ok
valid 40 Mpx progressive 352914 bytes accepted 0.07s ok
valid 40 Mpx progressive 444 704086 bytes accepted 0.13s ok
valid 40 Mpx progressive CMYK 626581 bytes accepted 0.17s ok
27-byte stub 27 bytes rejected 415 0.00s ok
first half + EOI 337948 bytes rejected 415 0.00s ok
first half, no EOI 337946 bytes rejected 415 0.00s ok
progressive half + EOI 308297 bytes rejected 415 0.00s ok
headers only + EOI 611 bytes rejected 415 0.01s ok
␍ ␍checker peak RSS, 40 Mpx baseline 1.7 MiB
␍ ␍checker peak RSS, 40 Mpx progressive 116.3 MiB
␍ ␍checker peak RSS, 40 Mpx progressive 444 230.6 MiB
␍ ␍checker peak RSS, 40 Mpx progressive CMYK 306.9 MiB
RESULT: 14/14
+25
View File
@@ -0,0 +1,25 @@
== 10 parallel uploads of 8674403 bytes, 3 rounds ==
upload statuses: {201: 30}
== 10 parallel downloads ==
download statuses: {200: 20}
== 10 parallel valid 40 Mpx progressive CMYK JPEGs (worst case for the checker), 3 rounds ==
upload statuses: {201: 30}
== 10 MiB + 1 byte, Content-Length: 100 requests, 10 at a time ==
{'413 application/json': 100}
== 10 MiB + 1 byte, chunked: 100 requests, 10 at a time ==
{'413 application/json': 100}
== 10 MiB + 1 byte, chunked in 64 KiB pieces: 100 requests, 10 at a time ==
{'413 application/json': 100}
== 8 MiB to a foreign chat: 100 requests, 10 at a time ==
{'404 application/json': 100}
== 8 MiB without session: 100 requests, 10 at a time ==
{'401 application/json': 100}
== 8 MiB with wrong magic: 100 requests, 10 at a time ==
{'415 application/json': 100}
== 8 MiB with wrong Content-Type: 100 requests, 10 at a time ==
{'415 application/json': 100}
== 70 KiB JSON message: 100 requests, 10 at a time ==
{'413 application/json': 100}
container events during the run: none
cgroup memory.peak, MiB: {'mtusi-lab4-api-1-1': 475.1, 'mtusi-lab4-api-2-1': 490.5, 'mtusi-lab4-nginx-1': 34.3}
PASS: LB stress
+25
View File
@@ -0,0 +1,25 @@
== 30 parallel uploads of 8674403 bytes, 2 rounds ==
upload statuses: {201: 60}
== 30 parallel downloads ==
download statuses: {200: 60}
== 30 parallel valid 40 Mpx progressive CMYK JPEGs (worst case for the checker), 2 rounds ==
upload statuses: {201: 60}
== 10 MiB + 1 byte, Content-Length: 30 requests, 30 at a time ==
{'413 application/json': 30}
== 10 MiB + 1 byte, chunked: 30 requests, 30 at a time ==
{'413 application/json': 30}
== 10 MiB + 1 byte, chunked in 64 KiB pieces: 30 requests, 30 at a time ==
{'413 application/json': 30}
== 8 MiB to a foreign chat: 30 requests, 30 at a time ==
{'404 application/json': 30}
== 8 MiB without session: 30 requests, 30 at a time ==
{'401 application/json': 30}
== 8 MiB with wrong magic: 30 requests, 30 at a time ==
{'415 application/json': 30}
== 8 MiB with wrong Content-Type: 30 requests, 30 at a time ==
{'415 application/json': 30}
== 70 KiB JSON message: 30 requests, 30 at a time ==
{'413 application/json': 30}
container events during the run: none
cgroup memory.peak, MiB: {'mtusi-lab4-api-1-1': 465.3, 'mtusi-lab4-api-2-1': 463.0, 'mtusi-lab4-nginx-1': 34.3}
PASS: LB stress
+12 -10
View File
@@ -1,23 +1,25 @@
payload bytes: 8674403
round 1 peak MiB per api: {'mtusi-lab4-api-1-1': 114.5, 'mtusi-lab4-api-2-1': 113.7} statuses=[201]
round 2 peak MiB per api: {'mtusi-lab4-api-1-1': 115.1, 'mtusi-lab4-api-2-1': 113.5} statuses=[201]
round 3 peak MiB per api: {'mtusi-lab4-api-1-1': 115.2, 'mtusi-lab4-api-2-1': 114.0} statuses=[201]
round 1 peak MiB per api: {'mtusi-lab4-api-2-1': 95.5, 'mtusi-lab4-api-1-1': 115.6} statuses=[201]
round 2 peak MiB per api: {'mtusi-lab4-api-2-1': 104.8, 'mtusi-lab4-api-1-1': 115.6} statuses=[201]
round 3 peak MiB per api: {'mtusi-lab4-api-2-1': 106.6, 'mtusi-lab4-api-1-1': 115.3} statuses=[201]
{
"payload_mib": 8.27,
"concurrency": 10,
"rounds": 3,
"idle_mib": {
"mtusi-lab4-api-1-1": 98.2,
"mtusi-lab4-api-2-1": 100.4
"mtusi-lab4-api-2-1": 87.2,
"mtusi-lab4-api-1-1": 87.8
},
"peak_mib": {
"mtusi-lab4-api-1-1": 115.2,
"mtusi-lab4-api-2-1": 114.0
"mtusi-lab4-api-2-1": 106.6,
"mtusi-lab4-api-1-1": 115.6
},
"container_limit_mib": 256,
"container_limit_mib": 512,
"statuses": {
"201": 30
},
"upload_seconds_median": 0.76,
"upload_seconds_max": 0.95
"upload_seconds_median": 0.63,
"upload_seconds_max": 0.82
}
peak=163 MiB oom_kill 0
peak=154 MiB oom_kill 0
+2 -5
View File
@@ -6,10 +6,7 @@ GET /messenger-attachments/ -> 403
GET /messenger-attachments/attachments/does-not-matter -> 403
GET /messenger-attachments?list-type=2 -> 403
== bucket policy ==
Container mtusi-lab4-minio-init-run-ace02363dd5e Creating
Container mtusi-lab4-minio-init-run-ace02363dd5e Created
Access permission for `local/messenger-attachments` is `private`
PASS: bucket is private
Container mtusi-lab4-minio-init-run-bb29f48b3cc4 Created
Container mtusi-lab4-minio-init-run-85f57841572d Creating
Container mtusi-lab4-minio-init-run-85f57841572d Created
Access permission for `local/messenger-attachments` is `private`
PASS: bucket is private
+6 -6
View File
@@ -1,11 +1,11 @@
baseline (data left by earlier tests): {"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 113, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 86, "seconds": 0.17, "stale_uploading": 0}
baseline (data left by earlier tests): {"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 366, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 203, "seconds": 0.253, "stale_uploading": 0}
== dry-run, grace=900 ==
{"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 2, "objects_scanned": 118, "orphan_objects": 0, "protected_fresh_objects": 2, "removed_rows": 0, "rows_scanned": 89, "seconds": 0.087, "stale_uploading": 1}
{"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 2, "objects_scanned": 371, "orphan_objects": 0, "protected_fresh_objects": 2, "removed_rows": 0, "rows_scanned": 206, "seconds": 0.264, "stale_uploading": 1}
ok dry-run: 1 new stale row (b), 2 old rows protected by young objects (a, h)
ok dry-run: 2 new missing objects (e, g)
ok dry-run changes nothing
== apply, grace=900 ==
{"deleted_objects": 0, "dry_run": false, "grace_seconds": 900, "marked_failed": 2, "missing_objects": 2, "objects_scanned": 118, "orphan_objects": 0, "protected_fresh_objects": 2, "removed_rows": 1, "rows_scanned": 89, "seconds": 0.1, "stale_uploading": 1}
{"deleted_objects": 0, "dry_run": false, "grace_seconds": 900, "marked_failed": 2, "missing_objects": 2, "objects_scanned": 371, "orphan_objects": 0, "protected_fresh_objects": 2, "removed_rows": 1, "rows_scanned": 206, "seconds": 0.273, "stale_uploading": 1}
ok old row whose object is young is kept (a)
ok stale row without object removed
ok fresh in-flight upload untouched
@@ -16,15 +16,15 @@ ok missing unused object marked failed
ok used attachment with object untouched
ok used attachment with lost object kept, marked failed
== apply after grace expired (grace=2 after 3s) ==
{"deleted_objects": 4, "dry_run": false, "grace_seconds": 2, "marked_failed": 1, "missing_objects": 1, "objects_scanned": 115, "orphan_objects": 1, "protected_fresh_objects": 0, "removed_rows": 3, "rows_scanned": 115, "seconds": 0.126, "stale_uploading": 3}
{"deleted_objects": 4, "dry_run": false, "grace_seconds": 2, "marked_failed": 1, "missing_objects": 1, "objects_scanned": 368, "orphan_objects": 1, "protected_fresh_objects": 0, "removed_rows": 3, "rows_scanned": 368, "seconds": 0.428, "stale_uploading": 3}
ok orphan object deleted after grace
ok expired in-flight row collected after grace
ok old row + object collected once the object is older than grace (a, h)
ok used attachment still untouched
== second apply is idempotent ==
{"deleted_objects": 0, "dry_run": false, "grace_seconds": 2, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 114, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 114, "seconds": 0.163, "stale_uploading": 0}
{"deleted_objects": 0, "dry_run": false, "grace_seconds": 2, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 367, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 367, "seconds": 0.457, "stale_uploading": 0}
ok repeat run changes nothing
== cost of a full walk, 1000 ready attachments ==
{"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 1114, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 1087, "seconds": 1.63, "stale_uploading": 0}
{"deleted_objects": 0, "dry_run": true, "grace_seconds": 900, "marked_failed": 0, "missing_objects": 0, "objects_scanned": 1367, "orphan_objects": 0, "protected_fresh_objects": 0, "removed_rows": 0, "rows_scanned": 1204, "seconds": 1.605, "stale_uploading": 0}
ok bulk walk finds nothing wrong
RESULT: 18/18 checks passed