fix: cleanupCtx 在启动时创建,可能在 shutdown 前过期

This commit is contained in:
hylaz
2026-03-04 17:43:34 +08:00
committed by lyingbug
parent a0952edc07
commit 8399527022
3 changed files with 24 additions and 18 deletions
+16
View File
@@ -88,6 +88,9 @@ func BuildContainer(container *dig.Container) *dig.Container {
must(container.Provide(initAntsPool))
must(container.Provide(initContextStorage))
// Register tracer cleanup handler (tracer needs to be available for cleanup registration)
must(container.Invoke(registerTracerCleanup))
// Register goroutine pool cleanup handler
must(container.Invoke(registerPoolCleanup))
@@ -740,6 +743,19 @@ func registerPoolCleanup(pool *ants.Pool, cleaner interfaces.ResourceCleaner) {
})
}
// registerTracerCleanup registers the tracer for cleanup
// Ensures proper cleanup of the tracer when application shuts down
// Parameters:
// - tracer: Tracer instance
// - cleaner: Resource cleaner
func registerTracerCleanup(tracer *tracing.Tracer, cleaner interfaces.ResourceCleaner) {
// Register the cleanup function - actual context will be provided during cleanup
cleaner.RegisterWithName("Tracer", func() error {
// Create context for cleanup with longer timeout for tracer shutdown
return tracer.Cleanup(context.Background())
})
}
// initDocReaderClient initializes the DocumentReader client (lightweight API).
func initDocReaderClient(cfg *config.Config) (interfaces.DocumentReader, error) {
addr := strings.TrimSpace(os.Getenv("DOCREADER_ADDR"))