fix(auto-cert): goroutine leaks

This commit is contained in:
Jacky 2025-02-05 20:59:09 +08:00
parent 07eba99f2b
commit a00a4f19d2
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 9 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

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