Skip to content

Commit

Permalink
Merge pull request #323 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Added trace dump for goRPC routines #313
  • Loading branch information
UltraInstinct14 authored Jun 15, 2023
2 parents d4a5341 + e3beb20 commit a12ca89
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
39 changes: 39 additions & 0 deletions loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import (
cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
tk "github.com/loxilb-io/loxilib"
"io"
"net"
"net/http"
_ "net/http/pprof"
"net/rpc"
"os"
"os/signal"
"runtime/debug"
Expand Down Expand Up @@ -75,6 +78,42 @@ type loxiNetH struct {
pFile *os.File
}

// LoxiXsyncMain - State Sync subsystem init
func LoxiXsyncMain() {
if opts.Opts.ClusterNodes == "none" {
return
}

// Stack trace logger
defer func() {
if e := recover(); e != nil {
if mh.logger != nil {
tk.LogIt(tk.LogCritical, "%s: %s", e, debug.Stack())
}
}
}()

for {
rpcObj := new(XSync)
err := rpc.Register(rpcObj)
if err != nil {
panic("Failed to register rpc")
}

rpc.HandleHTTP()

http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
io.WriteString(res, "loxilb-xsync\n")
})

listener := fmt.Sprintf(":%d", XSyncPort)
err = http.ListenAndServe(listener, nil)
if err != nil {
panic("Failed to rpc-listen")
}
}
}

// NodeWalker - an implementation of node walker interface
func (mh *loxiNetH) NodeWalker(b string) {
tk.LogIt(tk.LogDebug, "%s\n", b)
Expand Down
29 changes: 3 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,13 @@ package main

import (
"fmt"
"io"
"net/http"
"net/rpc"
"os"
"time"

"github.com/jessevdk/go-flags"
ln "github.com/loxilb-io/loxilb/loxinet"
opts "github.com/loxilb-io/loxilb/options"
"os"
"time"
)

// loxiXsyncMain - State Sync subsystem init
func loxiXsyncMain() {
if opts.Opts.ClusterNodes == "none" {
return
}
for {
rpcObj := new(ln.XSync)
rpc.Register(rpcObj)
rpc.HandleHTTP()

http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
io.WriteString(res, "loxilb-xsync\n")
})

listener := fmt.Sprintf(":%d", ln.XSyncPort)
http.ListenAndServe(listener, nil)
}
}

var version string = "0.8.7"
var buildInfo string = ""

Expand All @@ -66,7 +43,7 @@ func main() {
os.Exit(0)
}

go loxiXsyncMain()
go ln.LoxiXsyncMain()
// Need some time for RPC Handler to be up
time.Sleep(2 * time.Second)

Expand Down

0 comments on commit a12ca89

Please sign in to comment.