Skip to content

Commit

Permalink
cli: exit main loop after all relay exited
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Feb 5, 2022
1 parent 5afa351 commit a76a381
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/ehco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func createCliAPP() *cli.App {
},
&cli.IntFlag{
Name: "web_port",
Usage: "promtheus web expoter 的监听端口",
Usage: "prometheus web expoter 的监听端口",
EnvVars: []string{"EHCO_WEB_PORT"},
Value: 0,
Destination: &WebPort,
Expand Down Expand Up @@ -320,6 +320,7 @@ func start(ctx *cli.Context) error {
if len(cfg.RelayConfigs) > 0 {
go func() {
logger.Fatalf("[relay] StartRelayServers meet err=%v", startRelayServers(mainCtx, cfg))
cancel() // when all relay servers stop, mainCtx will be canceled
}()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
var (
DefaultDeadline = 30 * time.Second

Version = "1.1.1"
Version = "1.1.2"
GitBranch string
GitRevision string
BuildTime string
Expand Down
3 changes: 3 additions & 0 deletions internal/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func (r *Relay) RunLocalWSServer() error {
r.closeTcpF = func() error {
return lis.Close()
}
logger.Infof("[relay] Start WS relay %s", r.Name)
return server.Serve(lis)
}

Expand All @@ -224,6 +225,7 @@ func (r *Relay) RunLocalWSSServer() error {
r.closeTcpF = func() error {
return lis.Close()
}
logger.Infof("[relay] Start WSS relay %s", r.Name)
return server.Serve(tls.NewListener(lis, server.TLSConfig))
}

Expand All @@ -249,6 +251,7 @@ func (r *Relay) RunLocalMWSSServer() error {
r.closeTcpF = func() error {
return lis.Close()
}
logger.Infof("[relay] Start MWSS relay %s", r.Name)
go func() {
err := httpServer.Serve(tls.NewListener(lis, httpServer.TLSConfig))
if err != nil {
Expand Down

0 comments on commit a76a381

Please sign in to comment.