summaryrefslogtreecommitdiff
path: root/caddy.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-03-26 19:42:52 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-03-26 19:42:52 -0600
commita8dc73b4d9db5edf85e78314c9759b9d12a79b71 (patch)
treec1283aa94e2b2d605985130cdef070a24d03815e /caddy.go
parent86e2d1b0a48fbd84590291969611f1870471c3e0 (diff)
Performance testing Load function
Diffstat (limited to 'caddy.go')
-rw-r--r--caddy.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/caddy.go b/caddy.go
index 2f12776..40b73c5 100644
--- a/caddy.go
+++ b/caddy.go
@@ -3,10 +3,16 @@ package caddy2
import (
"encoding/json"
"fmt"
+ "log"
+ "runtime/debug"
"strings"
+ "sync"
"time"
)
+var currentCfg *Config
+var currentCfgMu sync.Mutex
+
// Start runs Caddy with the given config.
func Start(cfg Config) error {
cfg.runners = make(map[string]Runner)
@@ -26,16 +32,33 @@ func Start(cfg Config) error {
for name, r := range cfg.runners {
err := r.Run()
if err != nil {
+ // TODO: If any one has an error, stop the others
return fmt.Errorf("%s module: %v", name, err)
}
}
+ currentCfgMu.Lock()
+ if currentCfg != nil {
+ for _, r := range cfg.runners {
+ err := r.Cancel()
+ if err != nil {
+ log.Println(err)
+ }
+ }
+ }
+ currentCfg = &cfg
+ currentCfgMu.Unlock()
+
+ // TODO: debugging memory leak...
+ debug.FreeOSMemory()
+
return nil
}
// Runner is a thing that Caddy runs.
type Runner interface {
Run() error
+ Cancel() error
}
// Config represents a Caddy configuration.