Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go: fix MySQL connection port exhaustion under high concurrency (#19881)

Jin Hai882478e4e220
diff --git a/cmd/ragflow_server.go b/cmd/ragflow_server.go
index aa742a9043..d11d8140e8 100644
--- a/cmd/ragflow_server.go
+++ b/cmd/ragflow_server.go
@@ -526,10 +526,8 @@ func main() {
// stdout-only logger exists, so anything it logs is lost from the file.
// Side effects that log (DeepDoc registration) move below, after the
// real file-backed logger is up.
- needNativeDeepDoc := false
switch *arguments.mode {
case "api":
- needNativeDeepDoc = true
apiServerConfig := globalConfig.GetAPIServerConfig()
port := apiServerConfig.HTTPPort
if arguments.port != nil {
@@ -550,7 +548,6 @@ func main() {
serverName = fmt.Sprintf("admin_server_%d", port)
}
case "ingestor":
- needNativeDeepDoc = true
if serverName == "" {
uuid := utility.GenerateUUID()
serverName = fmt.Sprintf("ingestor_server_%s", uuid)
@@ -604,8 +601,10 @@ func main() {
// logger exists: its registration lines (and the Fatal abort on a missing
// backend) must land in the run's log file, not in the pre-config
// stdout-only window.
- if needNativeDeepDoc {
+ switch *arguments.mode {
+ case "api", "ingestor":
registerNativeDeepDoc()
+ default:
}
// Print all configuration settings
diff --git a/internal/dao/database.go b/internal/dao/database.go
index deea385f24..a458177e70 100644
--- a/internal/dao/database.go
+++ b/internal/dao/database.go
@@ -107,9 +107,9 @@ func InitDB(ctx context.Context, migrateDB bool) error {
}
// Set connection pool
- sqlDB.SetMaxIdleConns(10)
- sqlDB.SetMaxOpenConns(100)
- sqlDB.SetConnMaxLifetime(time.Hour)
+ sqlDB.SetMaxIdleConns(databaseConfig.MaxConnections)
+ sqlDB.SetMaxOpenConns(databaseConfig.MaxConnections)
+ sqlDB.SetConnMaxLifetime(time.Duration(databaseConfig.StaleTimeout) * time.Second)
// Auto migrate all dataModels
dataModels := []interface{}{
diff --git a/internal/entity/models/ollama.go b/internal/entity/models/ollama.go
index 5ce227032b..5abcf4a468 100644
--- a/internal/entity/models/ollama.go
+++ b/internal/entity/models/ollama.go
@@ -370,6 +370,7 @@ func (o *OllamaModel) Embed(ctx context.Context, modelName *string, request Embe
resp, err := o.baseModel.httpClient.Do(req)
if err != nil {
+ common.Error(fmt.Sprintf("failed to send request, response: %v", resp), err)
return nil, fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()