Part 03 · Spring Framework & Spring Boot · 3.1.12

Debug Spring trong production

Đi từ symptom và timeline tới resource queue, call path và evidence. Đổi annotation, pool hay JVM flag theo phỏng đoán thường chỉ dịch chuyển bottleneck.


Startup failure

Đọc exception chain và FailureAnalysis để xác định bean, dependency, condition hoặc property gây lỗi. Dùng condition report, bean definitions và configuration-binding errors. NoSuchMethodError thường là dependency mismatch; BeanCurrentlyInCreationException thường là cycle; port bind, certificate hoặc permission là environment/runtime concern.

Startup chậm

Đo bằng ApplicationStartup, Actuator startup endpoint hoặc JFR. Tìm component scan quá rộng, network call trong init, migrations, DNS/entropy, eager SDK và classpath lớn. Không bật lazy toàn cục trước khi biết bottleneck vì nó chuyển failure và latency sang request đầu tiên.

Request latency decomposition

Tách thời gian chờ servlet/event-loop, controller/service, transaction, connection pool, SQL, HTTP client pool, downstream và serialization. Trace chỉ call path; pool metrics cho saturation; thread dump cho blocked/waiting stacks; DB log và execution plan cho data path.

SignalKhả năngEvidence kế tiếp
Request queue tăng, CPU chưa caoThread/connection pool hoặc downstream saturation.Active, pending, acquisition latency và thread dump.
DB time tăngSlow query, lock wait, pool starvation.DB activity, lock graph, query plan, pool pending.
Latency tăng sau deployCode/config/schema/dependency regression.Canary comparison, deployment event, trace diff.
Memory tăng dầnUnbounded retention hoặc lifecycle leak.Class histogram, allocation/JFR, heap dominators.

Pool saturation

Servlet threads, Hikari connections, async executor, HTTP client connections và broker consumers là các queues nối tiếp. Tăng pool một chỗ có thể dồn tải sang downstream. Theo dõi active, pending, maximum, acquisition time, queue wait và rejection; capacity phải dựa trên bottleneck cuối cùng.

Transaction incidents

Điều tra long transaction, lock wait/deadlock, rollback-only, connection leak và REQUIRES_NEW starvation. Correlate database activity với request trace và transaction duration. Không bật SQL parameter logging chứa credential, token hoặc PII trong production.

Memory và resource retention

Nguồn phổ biến gồm classloader leak khi redeploy, unbounded cache, listeners, ThreadLocal/MDC, response buffering, executor queue và Hibernate persistence context quá lớn. Heap dump chứa dữ liệu nhạy cảm và có thể làm process pause; bắt đầu bằng histogram, allocation profiling hoặc JFR trước khi dump toàn heap.

Security incidents

Kiểm chain matcher/order, authentication failure so với access denied, session/context propagation, JWT issuer/audience/clock và object-level authorization. Audit mọi thay đổi security config, management exposure và dynamic log level; không ghi raw token để “debug nhanh”.

Rollout và readiness

Readiness chỉ true sau migration và warm-up cần thiết; schema thay đổi phải backward-compatible qua các version đang chạy. Drain traffic trước shutdown, theo dõi canary metrics và giữ rollback artifact/config. Startup success không đồng nghĩa application đã sẵn sàng phục vụ đúng.

Rollback caveat: application rollback không tự rollback database migration hoặc message đã publish. Deployment plan phải nêu forward fix, compatibility window và dữ liệu cần reconcile.
Quy trình điều tra: symptom → timeline → saturation/error signals → hypothesis có thể bác bỏ → evidence → thay đổi nhỏ nhất → verify bằng cùng signal. Ghi lại artifact và kết luận để incident sau không bắt đầu từ đầu.
Nguồn tham khảo