juanfont / headscale

An open source, self-hosted implementation of the Tailscale control server
BSD 3-Clause "New" or "Revised" License
23.72k stars 1.3k forks source link

[Bug] print wrong node information in poll.go #2183

Open PatrickHuang888 opened 1 month ago

PatrickHuang888 commented 1 month ago

Is this a support request?

Is there an existing issue for this?

Current Behavior

func (h *Headscale) newMapSession(
    ctx context.Context,
    req tailcfg.MapRequest,
    w http.ResponseWriter,
    node *types.Node,
) *mapSession {

// here passed node to print functions in init
    warnf, infof, tracef, errf := logPollFunc(req, node)

return &mapSession{

        node:   node,

        // Loggers
        warnf:  warnf,
        infof:  infof,
        tracef: tracef,
        errf:   errf,
    }
...

func (m *mapSession) serveLongPoll() {
    for {
        case update, ok := <-m.ch:

            // later override the node reference
            m.node, err = m.h.db.GetNodeByID(m.node.ID)

         switch update.Type {
            case types.StateFullUpdate:
                      // actually print old node not the m.node
                m.tracef("Sending Full MapResponse")
    }
}

Expected Behavior

maybe tracef reference to pointer of m.node ? not quit sure

func logPollFunc(
    mapRequest tailcfg.MapRequest,
    node **types.Node,
)
    mapSession:= &mapSession{
        node:   node,
    }
    warnf, infof, tracef, errf := logPollFunc(req, &mapSession.node)
    mapSession.warnf = warnf
    mapSession.infof = infof
    mapSession.tracef = tracef
    mapSession.errf = errf
    return mapSession

and is there any memory leak as tracef reference a unused node?

Steps To Reproduce

just read the code

Environment

- OS:
ubuntu
- Headscale version:
branch main

Runtime environment

Anything else?

No response