浏览代码

fix(auto-cert): goroutine leaks

Jacky 2 月之前
父节点
当前提交
a00a4f19d2
共有 5 个文件被更改,包括 9 次插入3 次删除
  1. 1 0
      .devcontainer/docker-compose.yml
  2. 1 1
      app/vite.config.ts
  3. 2 0
      internal/cert/auto_cert.go
  4. 1 0
      internal/cert/cert.go
  5. 4 2
      internal/cron/cron.go

+ 1 - 0
.devcontainer/docker-compose.yml

@@ -37,6 +37,7 @@ services:
     environment:
       - PEBBLE_VA_NOSLEEP=1
       - PEBBLE_VA_ALWAYS_VALID=1
+      - PEBBLE_WFE_NONCEREJECT=0
     networks:
       nginxui:
   challtestsrv:

+ 1 - 1
app/vite.config.ts

@@ -82,7 +82,7 @@ export default defineConfig(({ mode }) => {
           changeOrigin: true,
           secure: false,
           ws: true,
-          timeout: 5000,
+          timeout: 60000,
           agent: new Agent({
             keepAlive: false,
           }),

+ 2 - 0
internal/cert/auto_cert.go

@@ -113,4 +113,6 @@ func autoCert(certModel *model.Cert) {
 		notification.Error("Sync Certificate Error", err.Error())
 		return
 	}
+
+	close(logChan)
 }

+ 1 - 0
internal/cert/cert.go

@@ -33,6 +33,7 @@ func IssueCert(payload *ConfigPayload, logChan chan string, errChan chan error)
 	// initial a channelWriter to receive logs
 	cw := NewChannelWriter()
 	defer close(errChan)
+	defer close(cw.Ch)
 
 	// initial a logger
 	l := log.New(os.Stderr, "", log.LstdFlags)

+ 4 - 2
internal/cron/cron.go

@@ -1,13 +1,14 @@
 package cron
 
 import (
+	"time"
+
 	"github.com/0xJacky/Nginx-UI/internal/cert"
 	"github.com/0xJacky/Nginx-UI/internal/logrotate"
 	"github.com/0xJacky/Nginx-UI/query"
 	"github.com/0xJacky/Nginx-UI/settings"
 	"github.com/go-co-op/gocron/v2"
 	"github.com/uozi-tech/cosy/logger"
-	"time"
 )
 
 var s gocron.Scheduler
@@ -25,7 +26,8 @@ var logrotateJob gocron.Job
 func InitCronJobs() {
 	_, err := s.NewJob(gocron.DurationJob(30*time.Minute),
 		gocron.NewTask(cert.AutoCert),
-		gocron.WithSingletonMode(gocron.LimitModeWait))
+		gocron.WithSingletonMode(gocron.LimitModeWait),
+		gocron.JobOption(gocron.WithStartImmediately()))
 	if err != nil {
 		logger.Fatalf("AutoCert Err: %v\n", err)
 	}