Add: waitgroup for logger to wait for RPC server to be mounted, ref issue:- #299

Signed-off-by: Prajjawalk <prajjawalkhandelwal@gmail.com>
This commit is contained in:
Prajjawalk 2022-12-07 23:04:56 +05:30 committed by RichΛrd
parent f5d55038b6
commit 066185ee86
2 changed files with 9 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import (
"os/signal" "os/signal"
"regexp" "regexp"
"strings" "strings"
"sync"
"syscall" "syscall"
"time" "time"
@ -362,12 +363,16 @@ func Execute(options Options) {
rpcServer.Start() rpcServer.Start()
} }
var wg sync.WaitGroup
var restServer *rest.WakuRest var restServer *rest.WakuRest
if options.RESTServer.Enable { if options.RESTServer.Enable {
wg.Add(1)
restServer = rest.NewWakuRest(wakuNode, options.RESTServer.Address, options.RESTServer.Port, options.RESTServer.Admin, options.RESTServer.Private, options.RESTServer.RelayCacheCapacity, logger) restServer = rest.NewWakuRest(wakuNode, options.RESTServer.Address, options.RESTServer.Port, options.RESTServer.Admin, options.RESTServer.Private, options.RESTServer.RelayCacheCapacity, logger)
restServer.Start() restServer.Start(&wg)
} }
wg.Wait()
logger.Info("Node setup complete") logger.Info("Node setup complete")
// Wait for a SIGINT or SIGTERM signal // Wait for a SIGINT or SIGTERM signal

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"sync"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/waku-org/go-waku/waku/v2/node" "github.com/waku-org/go-waku/waku/v2/node"
@ -46,7 +47,8 @@ func NewWakuRest(node *node.WakuNode, address string, port int, enableAdmin bool
return wrpc return wrpc
} }
func (r *WakuRest) Start() { func (r *WakuRest) Start(wg *sync.WaitGroup) {
defer wg.Done()
go r.relayService.Start() go r.relayService.Start()
go func() { go func() {
_ = r.server.ListenAndServe() _ = r.server.ListenAndServe()