Dokploy monitoring API returns partial container metrics with HTTP 200 when a row read fails

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

Maintainer thường phản hồi trong vòng 1 ngày

@PAtreju đang làm issue này rồi.

Từ ngày 17/11/2026.

  • #6058 của @PAtreju — đang mở

Đá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
88/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ệ
go, sqlite
Lĩnh vực
backend, observability

Hướng nghiên cứu

Đọc apps/monitoring/database/containers.go, tập trung vào GetAllMetricsContainer và GetLastNContainerMetrics, sau đó xem lại cách tái hiện trong issue. Kiểm tra cách mỗi reader xử lý lỗi sau khi duyệt qua rows; công việc hoàn tất khi lỗi trong quá trình duyệt được trả về dưới dạng lỗi và các bài kiểm tra cơ sở dữ liệu hiện có đều chạy thành công, đồng thời handler trong apps/monitoring/main.go trả về HTTP 500 cho những lỗi đó.

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

Mô tả

bug

Dokploy monitoring API returns partial container metrics with HTTP 200 when a row read fails

Environment

  • Dokploy commit 3e75dc64f391316df63a99fbef3e0df5bf7b9350
  • Go 1.26, Linux (golang:1.26 image); the same code path runs on the released SQLite build

Summary

apps/monitoring/database/containers.go iterates rows.Next() in both metric readers but
never checks rows.Err(). When the SQLite driver fails mid-iteration (I/O error, corruption,
interrupted read), the loop simply ends and the function returns the rows collected so far
with a nil error. GET /metrics/containers?limit=all therefore answers 200 OK with a
truncated time series, and the dashboard renders the gap as if the metrics had ended.

Root cause

database/sql.Rows.Next returns false both when the result set ends normally and when the
driver reports an error; the error is deferred to Rows.Err(). Both readers only inspect the
error from Scan, so an iteration error looks identical to a clean end of data:

for rows.Next() {          // false on error AND on success
    if err := rows.Scan(&metricsJSON); err != nil {
        return nil, err
    }
    ...
}
return metrics, nil        // iteration error is never read

Because no rows.Err() call follows the loop, the driver error (disk I/O error, a decode
failure, a cancelled context, …) is discarded and the collected prefix is indistinguishable
from a complete, successful result. The HTTP handler only branches on the returned error, so
it answers 200 with the partial slice.

Affected code

  • apps/monitoring/database/containers.go — GetAllMetricsContainer (loop ends with
    return metrics, nil, no rows.Err()).
  • apps/monitoring/database/containers.go — GetLastNContainerMetrics has the same shape.
  • apps/monitoring/main.go — GET /metrics/containers returns c.JSON(metrics) whenever
    err == nil.

Reproduction

A driver that yields one row and then fails is enough; no database file is needed. Save this
as apps/monitoring/database/rows_err_test.go:

package database

import (
	"context"
	"database/sql"
	"database/sql/driver"
	"errors"
	"io"
	"testing"
)

type failDriver struct{}

func (failDriver) Open(string) (driver.Conn, error) { return failConn{}, nil }

type failConn struct{}

func (failConn) Prepare(string) (driver.Stmt, error) { return nil, io.EOF }
func (failConn) Close() error                        { return nil }
func (failConn) Begin() (driver.Tx, error)           { return nil, io.EOF }
func (failConn) QueryContext(context.Context, string, []driver.NamedValue) (driver.Rows, error) {
	return &failRows{}, nil
}

type failRows struct{ step int }

func (r *failRows) Columns() []string { return []string{"metrics_json"} }
func (r *failRows) Close() error      { return nil }
func (r *failRows) Next(dest []driver.Value) error {
	if r.step == 0 {
		r.step++
		dest[0] = `{"timestamp":"2026-01-01T00:00:00Z","CPU":1}`
		return nil
	}
	return errors.New("disk I/O error while reading container_metrics")
}

func TestRowsErrIsReported(t *testing.T) {
	sql.Register("faildriver", failDriver{})
	db, _ := sql.Open("faildriver", "")
	metrics, err := (&DB{DB: db}).GetAllMetricsContainer("web")
	if err == nil {
		t.Fatalf("returned %d partial metrics with nil error", len(metrics))
	}
}

Run go test -run TestRowsErrIsReported ./database from apps/monitoring. Observed:

metrics=1 err=<nil>
BUG: driver error was swallowed; returned 1 partial metrics with nil error

Expected behavior

A row-iteration failure is surfaced: GetAllMetricsContainer / GetLastNContainerMetrics
return the error, and GET /metrics/containers answers 500 with the error message instead
of a truncated series.

Actual behavior

The partial slice is returned with nil error and served as 200 OK, so monitoring charts
silently lose data.

Suggested fix

After each for rows.Next() { ... } loop:

if err := rows.Err(); err != nil {
    return nil, err
}
return metrics, nil
Ngôn ngữ chính
TypeScript
Star
38.8k
Fork
3.2k
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
110

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 Dokploy/dokploy

Tất cả issue của Dokploy/dokploy

Issue tương tự

Thêm issue về TypeScript

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.