Fixes in Noise poll (clients should work now)

This commit is contained in:
Juan Font Alonso 2022-08-14 21:10:08 +02:00
parent ab18c721bb
commit e640c6df05
2 changed files with 38 additions and 21 deletions

View File

@ -369,8 +369,9 @@ func (h *Headscale) handleNoiseMachineRegistrationNew(
// The machine registration is new, redirect the client to the registration URL // The machine registration is new, redirect the client to the registration URL
log.Debug(). log.Debug().
Caller().
Str("machine", registerRequest.Hostinfo.Hostname). Str("machine", registerRequest.Hostinfo.Hostname).
Msg("The node is sending us a new NodeKey, sending auth url") Msg("The node seems to be new, sending auth url")
if h.cfg.OIDC.Issuer != "" { if h.cfg.OIDC.Issuer != "" {
resp.AuthURL = fmt.Sprintf( resp.AuthURL = fmt.Sprintf(
"%s/oidc/register/%s", "%s/oidc/register/%s",

View File

@ -298,10 +298,19 @@ func (h *Headscale) NoisePollNetMapStream(
Err(err). Err(err).
Msg("Cannot write data") Msg("Cannot write data")
break return
} }
if f, ok := writer.(http.Flusher); ok {
f.Flush() flusher, ok := writer.(http.Flusher)
if !ok {
log.Error().
Caller().
Str("handler", "PollNetMapStream").
Str("machine", machine.Hostname).
Str("channel", "pollData").
Msg("Cannot cast writer to http.Flusher")
} else {
flusher.Flush()
} }
log.Trace(). log.Trace().
Str("handler", "NoisePollNetMapStream"). Str("handler", "NoisePollNetMapStream").
@ -323,7 +332,7 @@ func (h *Headscale) NoisePollNetMapStream(
// client has been removed from database // client has been removed from database
// since the stream opened, terminate connection. // since the stream opened, terminate connection.
break return
} }
now := time.Now().UTC() now := time.Now().UTC()
machine.LastSeen = &now machine.LastSeen = &now
@ -353,27 +362,34 @@ func (h *Headscale) NoisePollNetMapStream(
case data := <-keepAliveChan: case data := <-keepAliveChan:
log.Trace(). log.Trace().
Str("handler", "NoisePollNetMapStream"). Str("handler", "PollNetMapStream").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Int("bytes", len(data)). Int("bytes", len(data)).
Msg("Sending keep alive message") Msg("Sending keep alive message")
_, err := writer.Write(data) _, err := writer.Write(data)
if f, ok := writer.(http.Flusher); ok {
f.Flush()
}
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "NoisePollNetMapStream"). Str("handler", "PollNetMapStream").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Err(err). Err(err).
Msg("Cannot write keep alive message") Msg("Cannot write keep alive message")
break return
} }
flusher, ok := writer.(http.Flusher)
if !ok {
log.Error().
Caller().
Str("handler", "PollNetMapStream").
Str("machine", machine.Hostname).
Str("channel", "keepAlive").
Msg("Cannot cast writer to http.Flusher")
} else {
flusher.Flush()
}
log.Trace(). log.Trace().
Str("handler", "NoisePollNetMapStream"). Str("handler", "NoisePollNetMapStream").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
@ -394,7 +410,7 @@ func (h *Headscale) NoisePollNetMapStream(
// client has been removed from database // client has been removed from database
// since the stream opened, terminate connection. // since the stream opened, terminate connection.
break return
} }
now := time.Now().UTC() now := time.Now().UTC()
machine.LastSeen = &now machine.LastSeen = &now
@ -415,7 +431,7 @@ func (h *Headscale) NoisePollNetMapStream(
Msg("Machine updated successfully after sending keep alive") Msg("Machine updated successfully after sending keep alive")
} }
break return
case <-updateChan: case <-updateChan:
log.Trace(). log.Trace().
@ -456,7 +472,7 @@ func (h *Headscale) NoisePollNetMapStream(
updateRequestsSentToNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "failed"). updateRequestsSentToNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "failed").
Inc() Inc()
break return
} }
if f, ok := writer.(http.Flusher); ok { if f, ok := writer.(http.Flusher); ok {
@ -489,7 +505,7 @@ func (h *Headscale) NoisePollNetMapStream(
// client has been removed from database // client has been removed from database
// since the stream opened, terminate connection. // since the stream opened, terminate connection.
break return
} }
now := time.Now().UTC() now := time.Now().UTC()
@ -519,7 +535,7 @@ func (h *Headscale) NoisePollNetMapStream(
Msgf("%s is up to date", machine.Hostname) Msgf("%s is up to date", machine.Hostname)
} }
break return
case <-ctx.Done(): case <-ctx.Done():
log.Info(). log.Info().
@ -540,7 +556,7 @@ func (h *Headscale) NoisePollNetMapStream(
// client has been removed from database // client has been removed from database
// since the stream opened, terminate connection. // since the stream opened, terminate connection.
break return
} }
now := time.Now().UTC() now := time.Now().UTC()
machine.LastSeen = &now machine.LastSeen = &now
@ -554,7 +570,7 @@ func (h *Headscale) NoisePollNetMapStream(
Msg("Cannot update machine LastSeen") Msg("Cannot update machine LastSeen")
} }
break return
} }
} }
} }
@ -606,7 +622,7 @@ func (h *Headscale) noiseScheduledPollWorker(
log.Debug(). log.Debug().
Str("func", "scheduledPollWorker"). Str("func", "scheduledPollWorker").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Sending update request") Msg("Sending noise update request")
updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "scheduled-update"). updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "scheduled-update").
Inc() Inc()
updateChan <- struct{}{} updateChan <- struct{}{}