App Framework S3 client leaks one idle connection per poll; pod runs out of ports and apps stop installing

Đang mở Phù hợp với người mới
#1,888 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
aws, go, kubernetes
Lĩnh vực
backend, networking

Hướng nghiên cứu

Bắt đầu với pkg/splunk/client/storage/aws/s3client.go và theo dõi cách InitClientConfig tạo các transport cho mỗi lần thăm dò kho ứng dụng; so sánh cách thiết lập transport trong pkg/splunk/client/splunk/splunkclient.go. Thêm kiểm tra hồi quy cho các kết nối nhàn rỗi và chạy các bài kiểm thử Go liên quan. Hoàn thành khi các lần thăm dò lặp lại không còn để lại một kết nối S3 nhàn rỗi cho mỗi lần thăm dò.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

With the App Framework enabled on a SearchHeadCluster (S3 provider aws, an S3-compatible endpoint), the operator leaks one idle TCP connection to the S3 endpoint per app repo poll. After a few weeks the pod runs out of local ports, every bucket listing fails, and app uploads silently stop installing.

Environment

  • Splunk Operator 3.0.0, and the same code in 3.2.0 (reproduced on 3.2.0 too)
  • Kubernetes 1.35 (RKE2)
  • App Framework: one SearchHeadCluster, one app source, appsRepoPollIntervalSeconds: 61, S3-compatible object store over plain HTTP

What we saw

  • After 23 days the operator pod had 28,355 TCP sockets open, against an ephemeral port range of 32768 60999 (28,232 ports).
  • Every reconcile then failed listing the bucket:
    dial tcp <s3-endpoint>:3900: connect: cannot assign requested address
  • The object store itself was healthy and reachable from other pods. Restarting the operator pod fixed it immediately.
  • After a restart, open connections to the S3 endpoint grow by about one per minute (one per poll) and never drop: 5 after 10 min, 10 after 15 min, 33 after 48 min, 59 after about 100 min. At that rate the ports run out in roughly 20 days.
  • Connections to splunkd (8089) also start a new transport per client but level off around 120 to 140, presumably because splunkd closes idle keep-alive connections. The S3 endpoint does not, so those accumulate.

Cause

InitClientConfig in pkg/splunk/client/storage/aws/s3client.go builds a new http.Transport (and http.Client) on every call, with no IdleConnTimeout:

tr := &http.Transport{
    TLSClientConfig: &tls.Config{
        MinVersion: tls.VersionTLS12,
    },
}
tr.ForceAttemptHTTP2 = true
httpClient := http.Client{
    Transport: tr,
    Timeout:   httpClientTimeout * time.Second,
}

It is called for every app repo check (GetRemoteStorageClient logs creating the client on each poll). Each discarded transport keeps its idle keep-alive connection in its pool, and since IdleConnTimeout is 0 (no limit), the connection is never closed unless the server closes it.

NewSplunkClient in pkg/splunk/client/splunk/splunkclient.go has the same per-call transport pattern.

Suggested fix

Either of these, smallest first:

  1. Set an idle timeout on the transport, e.g. IdleConnTimeout: 90 * time.Second (the http.DefaultTransport value), so abandoned pools close their connections.
  2. Build the transport once (package level, or cached per endpoint) and reuse it across calls, which also restores connection reuse.

Calling tr.CloseIdleConnections() when the client is no longer needed would also work but is easier to miss on error paths.

Workaround

Restart the operator deployment periodically (we run a weekly kubectl rollout restart deployment splunk-operator-controller-manager).

Ngôn ngữ chính
Go
Star
260
Fork
134
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của splunk/splunk-operator

Tất cả issue của splunk/splunk-operator

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.