From 8d406bd2e69996f4b8ed3129dee1492dc6ea2d20 Mon Sep 17 00:00:00 2001 From: OliverW <1225191678@qq.com> Date: Wed, 7 Jan 2026 10:07:18 +0800 Subject: [PATCH] fix: prevent MinIO health check failure in multi-bucket mode (#12446) ### What problem does this PR solve? - Fixes the health check failure in multi-bucket MinIO environments. Previously, health checks would fail because the default "ragflow-bucket" did not exist. This caused false negatives for system health. - Also removes the _health_check write in single-bucket mode to avoid side effects (minor optimization). ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/utils/minio_conn.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/rag/utils/minio_conn.py b/rag/utils/minio_conn.py index 2c7b35ff6..595a00d1c 100644 --- a/rag/utils/minio_conn.py +++ b/rag/utils/minio_conn.py @@ -18,7 +18,7 @@ import logging import time from minio import Minio from minio.commonconfig import CopySource -from minio.error import S3Error +from minio.error import S3Error, ServerError, InvalidResponseError from io import BytesIO from common.decorator import singleton from common import settings @@ -97,19 +97,28 @@ class RAGFlowMinio: self.conn = None def health(self): - bucket = self.bucket if self.bucket else "ragflow-bucket" - fnm = "_health_check" - if self.prefix_path: - fnm = f"{self.prefix_path}/{fnm}" - binary = b"_t@@@1" - # Don't try to create bucket - it should already exist - # if not self.conn.bucket_exists(bucket): - # self.conn.make_bucket(bucket) - r = self.conn.put_object(bucket, fnm, - BytesIO(binary), - len(binary) - ) - return r + """ + Check MinIO service availability. + """ + try: + if self.bucket: + # Single-bucket mode: check bucket exists only (no side effects) + exists = self.conn.bucket_exists(self.bucket) + + # Historical: + # - Previously wrote "_health_check" to verify write permissions + # - Previously auto-created bucket if missing + + return exists + else: + # Multi-bucket mode: verify MinIO service connectivity + self.conn.list_buckets() + return True + except (S3Error, ServerError, InvalidResponseError): + return False + except Exception as e: + logging.warning(f"Unexpected error in MinIO health check: {e}") + return False @use_default_bucket @use_prefix_path