[CLAUDE] PurchaseEvaluation: YC-028 sự cố prod A/059 — FE tách "404 thật ⟂ lỗi hệ thống" 5 site ×2 app + guard disk/orphan vào runbook+cicd-monitor

Sự cố 2 tầng (đã giải trọn trong phiên, chi tiết runs/2026-08-10-S189-bookstart-open/run.md + WAL):
- T1: ổ C VPS 0 byte (gitea repo-archive 16,49GB + npm-cache SYSTEM 12,76GB) → SQL Error -2
  → "ko duyệt được" rồi FE vẽ mọi lỗi thành "Không tìm thấy phiếu" (#44). Dọn ~30GB cache
  + AUTO_CLOSE OFF ×3 DB + gỡ nén NTFS 4 file template (#88 tái phát).
- T2: 3 sshd mồ côi (lệnh đo ssh bị cắt output) bão hòa 3/3 core → mọi GET detail 5-47s,
  A/059 (5 NCC) vượt trần hủy ~30s của FE. Kill orphan → A/059 47s→0,38s · phiếu bé 0,17s.

Code (5 site cùng lớp, SHA-mirror 4 cặp MATCH, build ×2 xanh):
- lib/apiError.ts +isNotFound(err) — chỉ 404 mới được nói "không tìm thấy"
- PurchaseEvaluationsListPage (inline + overlay + fullpage) + KhkkListPage + KhkkCreatePage:
  detail.isError && !404 → "Hệ thống đang chậm hoặc lỗi khi tải phiếu — thử lại (refetch)"

Ops-guard (YC-028 (4)): cicd-monitor persona +bước 1b server-health (fsutil free <5GB = FAIL,
CPU-delta tìm orphan) · iis-deploy-runbook +§"Disk-free + orphan guard" + sửa path log Serilog
sai (Logs\log-*.txt → logs\solution-erp-*.log, đo thật). (6) đóng: log 10/08 mất do đợt "giải
phóng dung lượng" hôm qua (retention 30 file config đúng). (3B) cron archive_cleanup Gitea +
decompress Vietreport_Master = chờ ngoài giờ (restart service dùng chung VIETREPORT).

Sổ: +YC-028 (nguyên văn + 2 tầng đã xử). Squash wal: trailing theo §5.0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-08-11 11:25:51 +07:00
parent 9b3c0edba3
commit 92d8215a62
12 changed files with 175 additions and 47 deletions

View File

@ -78,8 +78,9 @@ Get-Website -Name "SolutionErp-*" | Format-Table Name, State, Bindings
### Xem log API
```powershell
# Serilog file rolling daily
Get-Content "C:\inetpub\solution-erp\api\Logs\log-$(Get-Date -Format 'yyyyMMdd').txt" -Tail 50
# Serilog file rolling daily (path ĐO THẬT @S189 2026-08-11 — bản cũ ghi `Logs\log-*.txt` SAI;
# config sống: appsettings.Production.json:42 `logs/solution-erp-.log`, retained 30, roll 100MB)
Get-Content "C:\inetpub\solution-erp\api\logs\solution-erp-$(Get-Date -Format 'yyyyMMdd').log" -Tail 50
# IIS log
Get-Content "C:\inetpub\logs\LogFiles\W3SVC<ID>\u_ex$(Get-Date -Format 'yyMMdd').log" -Tail 30
@ -99,6 +100,30 @@ curl http://127.0.0.1:5443/health/ready
curl https://api.solutions.com.vn/health/ready
```
### 🔴 Disk-free + orphan guard (S189 2026-08-11 — sự cố YC-028, PHẢI check khi prod chậm/500)
```powershell
# 1. Disk C: — sự cố thật: 0 byte (repo-archive Gitea 16,5GB + npm-cache SYSTEM 12,8GB)
# → SQL Error -2 (không mở nổi connection) → FE hiện "Không tìm thấy phiếu" (#44 class)
fsutil volume diskfree C: # free < 5GB = ĐỎ; cache tự phình: C:\gitea\data\repo-archive
# (xóa an toàn — Gitea tự tái tạo) + npm-cache SYSTEM (CI)
# 2. CPU orphan — sự cố thật: 3 sshd mồ côi (ssh bị cắt output giữa chừng) ăn 3/3 core
# → mọi API 5-47s, SQL wait ASYNC_NETWORK_IO (client đói CPU không nhận nổi data)
$a=@{}; Get-Process | ForEach-Object { $a[$_.Id]=$_.CPU }; Start-Sleep 5
Get-Process | ForEach-Object { if($a.ContainsKey($_.Id)){ $d=$_.CPU-$a[$_.Id]; if($d -ge 1){ "$($_.Name) $($_.Id) $([math]::Round($d,1))" } } }
# sshd/powershell lạ ăn ≥1 core-s/5s → kill (CHỪA chuỗi tổ tiên session mình)
# 3. NTFS compression trên .mdf/.ldf (gotcha #88 — "giải phóng dung lượng" nén khi ổ cạn)
Get-ChildItem 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQLEXPRESS\MSSQL\DATA' -File |
Where-Object { $_.Attributes -match 'Compressed' } # có kết quả = compact /u (DB offline nếu đang mở)
# 4. AUTO_CLOSE phải OFF (đã set @S189 — ON làm mỗi connection mở lại DB ~5s)
sqlcmd -S .\SQLEXPRESS -E -W -Q "SELECT name,is_auto_close_on FROM sys.databases WHERE database_id>4"
```
🔴 **Bài `ssh … | head` (S189):** cắt output sớm làm ssh client thoát nhưng **process phía Windows-OpenSSH chạy tiếp** → orphan spin ăn core. Lệnh ssh dài: bọc `Select-Object -First N` phía REMOTE, đừng `| head` phía local.
## Let's Encrypt cert — win-acme
### Check trạng thái