Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xffffharry committed Nov 3, 2023
1 parent 97b7d97 commit 52ea3cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
12 changes: 12 additions & 0 deletions cmd/cdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"os/signal"
"strconv"
"strings"
"syscall"

Expand All @@ -29,6 +30,14 @@ var MainCommand = &cobra.Command{
var configPath string

func init() {
//
{
e, err := strconv.ParseBool(os.Getenv("CDNS_LISTENER_ENABLE_PANIC"))
if err == nil && e {
constant.ListenerEnablePainc = true
}
}
//
MainCommand.PersistentFlags().StringVarP(&configPath, "config", "c", "config.yaml", "config file path")
MainCommand.AddCommand(versionCommand)
}
Expand All @@ -55,6 +64,9 @@ func run() int {
coreLogger.Infof("cdns %s", constant.Version)
coreLogger.Infof("plugin matcher: %s", strings.Join(plugin.PluginMatcherTypes(), ", "))
coreLogger.Infof("plugin executor: %s", strings.Join(plugin.PluginExecutorTypes(), ", "))
if constant.ListenerEnablePainc {
coreLogger.Infof("debug: listener enable painc")
}
go signalHandle(cancel, coreLogger)
err = c.Run()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions constant/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package constant

var ListenerEnablePainc = false
14 changes: 7 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (c *Core) Run() error {
err = starter.Start()
if err != nil {
err = fmt.Errorf("start upstream[%s] failed: %s", u.Tag(), err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand All @@ -267,7 +267,7 @@ func (c *Core) Run() error {
err = c.ntpServer.Start()
if err != nil {
err = fmt.Errorf("start ntp server failed: %s", err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
defer func() {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (c *Core) Run() error {
err = starter.Start()
if err != nil {
err = fmt.Errorf("start plugin matcher[%s] failed: %s", pm.Tag(), err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (c *Core) Run() error {
err = starter.Start()
if err != nil {
err = fmt.Errorf("start plugin executor[%s] failed: %s", pe.Tag(), err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand All @@ -343,7 +343,7 @@ func (c *Core) Run() error {
err = w.Check()
if err != nil {
err = fmt.Errorf("check workflow[%s] failed: %s", w.Tag(), err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand All @@ -369,7 +369,7 @@ func (c *Core) Run() error {
err = starter.Start()
if err != nil {
err = fmt.Errorf("start listener[%s] failed: %s", l.Tag(), err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand All @@ -387,7 +387,7 @@ func (c *Core) Run() error {
err = c.apiServer.Start()
if err != nil {
err = fmt.Errorf("start api server failed: %s", err)
c.rootLogger.Fatal(err)
c.coreLogger.Fatal(err)
return err
}
}
Expand Down
15 changes: 9 additions & 6 deletions listener/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/rnetx/cdns/adapter"
"github.com/rnetx/cdns/constant"
"github.com/rnetx/cdns/log"
"github.com/rnetx/cdns/utils"

Expand Down Expand Up @@ -157,12 +158,14 @@ func listenerHandle(ctx context.Context, listener string, logger log.Logger, wor
ctx = adapter.SaveLogContext(ctx, dnsCtx)
messageInfo := reqMessageInfo(req)
logger.InfofContext(ctx, "new request: %s", messageInfo)
defer func() {
err := recover()
if err != nil {
logger.FatalfContext(ctx, "handle request failed: %s, error(painc): %s", messageInfo, err)
}
}()
if !constant.ListenerEnablePainc {
defer func() {
err := recover()
if err != nil {
logger.FatalfContext(ctx, "handle request failed: %s, error(painc): %s", messageInfo, err)
}
}()
}
_, err := workflow.Exec(ctx, dnsCtx)
if err != nil {
logger.ErrorfContext(ctx, "handle request failed: %s, error: %s", messageInfo, err)
Expand Down

0 comments on commit 52ea3cb

Please sign in to comment.