Skip to content

Commit

Permalink
Fix log lines getting spliced from uncloned byte array
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 28, 2024
1 parent 9a514ad commit 2788154
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion adminui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (au *AdminUI) serverInfo(w http.ResponseWriter, r *http.Request) {
func (au *AdminUI) consoleLog(w http.ResponseWriter, r *http.Request) {
d := LogLinesDTO{}

for _, li := range au.logQueue.ReadAll() {
for _, li := range au.logQueue.w.ReadAll() {
d.LogItems = append(d.LogItems, string(li))
}

Expand Down
14 changes: 12 additions & 2 deletions adminui/ui_webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AdminUI struct {

oidcProvider rp.RelyingParty

logQueue *queue.Queue[[]byte]
logQueue *clonerWriter

listenerEvents struct {
clusterHealth string
Expand All @@ -47,6 +47,14 @@ type AdminUI struct {
csrfHeaderName string
}

type clonerWriter struct {
w *queue.Queue[string]
}

func (c *clonerWriter) Write(b []byte) (int, error) {
return c.w.Write(string(b))
}

func New(firewall *router.Firewall, errs chan<- error) (ui *AdminUI, err error) {

if firewall == nil {
Expand All @@ -55,7 +63,9 @@ func New(firewall *router.Firewall, errs chan<- error) (ui *AdminUI, err error)

var adminUI AdminUI
adminUI.firewall = firewall
adminUI.logQueue = queue.NewQueue[[]byte](40)
adminUI.logQueue = &clonerWriter{
queue.NewQueue[string](40),
}

adminUI.ctrl = wagctl.NewControlClient(config.Values.Socket)

Expand Down

0 comments on commit 2788154

Please sign in to comment.