Skip to content

Commit

Permalink
fix panic reboot in demo mode; clean up some LogDebugs
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfeldman committed Jan 14, 2025
1 parent abe90db commit 4ba3982
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
18 changes: 9 additions & 9 deletions pkg/device/device-linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ func (d *device) _buildOS() error {
var err error

d.ServeMux = http.NewServeMux()
d.views = make(views)

// Preserve views in case of device reboot
if d.views == nil {
d.views = make(views)
}

// Build device's layered FS. fs is stacked on top of
// deviceFs, so fs:foo.tmpl will override deviceFs:foo.tmpl,
Expand Down Expand Up @@ -237,13 +241,10 @@ func deviceNotFound(id string) error {

func (d *device) routeDown(pkt *Packet) {

d.RLock()
defer d.RUnlock()

// If device is running on 'metal', this is the packet's final
// destination.
if d._isSet(flagMetal) {
d._handle(pkt)
if d.isSet(flagMetal) {
d.handle(pkt)
return
}

Expand Down Expand Up @@ -646,18 +647,17 @@ func (d *device) demoReboot(pkt *Packet) {

// Go offline for 3 seconds
d.unSet(flagOnline)
pkt.SetPath("/state").Marshal(d.State).BroadcastUp()
pkt.SetPath("/offline").BroadcastUp()
time.Sleep(3 * time.Second)

model, _ := Models[d.Model]

d.build(model.Maker)
d.setupAPI()
d.setup()
d.startDemo()

// Come back online
pkt.SetPath("/state").Marshal(d.State).BroadcastUp()
pkt.SetPath("/online").Marshal(d.State).BroadcastUp()
}

func (d *device) handleReboot(pkt *Packet) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (d *device) _formConfig(rawQuery string) (changed bool, err error) {
return false, err
}

//LogDebug("Proposed DeployParams:", proposedParams)
//LogError("Proposed", "DeployParams", proposedParams, "values", values)

// Form-decode these values into the device to configure the device
if err := decode(d.State, values); err != nil {
Expand Down
10 changes: 2 additions & 8 deletions pkg/device/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (h *PacketHandler[T]) cb(pkt *Packet) {
// PacketHandlers is a map of Handlers, keyed by path.
type PacketHandlers map[string]packetHandler

func (d *device) _handle(pkt *Packet) {
if d._isSet(flagOnline) || pkt.Path == "/online" {
func (d *device) handle(pkt *Packet) {
if d.isSet(flagOnline) || pkt.Path == "/online" {
if handler, ok := d.PacketHandlers[pkt.Path]; ok {
LogDebug("Handling", "pkt", pkt)
d.stateMu.Lock()
Expand All @@ -37,9 +37,3 @@ func (d *device) _handle(pkt *Packet) {
}
}
}

func (d *device) handle(pkt *Packet) {
d.RLock()
defer d.RUnlock()
d._handle(pkt)
}
2 changes: 1 addition & 1 deletion pkg/device/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func routesBuild(root *device) {
child.RUnlock()
}

LogInfo("Routes", "map[dst]nexthop", routes)
LogDebug("Routes", "map[dst]nexthop", routes)
}

func downlinksRoute(p *Packet) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/device/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func Run() {

func logBuildInfo() {
if buildInfo, ok := debug.ReadBuildInfo(); ok {
LogInfo("Build Info:")
LogInfo("Go Version:", "version", buildInfo.GoVersion)
LogInfo("Path", "path", buildInfo.Path)
LogDebug("Build Info:")
LogDebug("Go Version:", "version", buildInfo.GoVersion)
LogDebug("Path", "path", buildInfo.Path)
for _, setting := range buildInfo.Settings {
LogInfo("Setting", setting.Key, setting.Value)
LogDebug("Setting", setting.Key, setting.Value)
}
for _, dep := range buildInfo.Deps {
LogInfo("Dependency", "Path", dep.Path, "Version", dep.Version, "Replace", dep.Replace)
LogDebug("Dependency", "Path", dep.Path, "Version", dep.Version, "Replace", dep.Replace)
}
}
LogInfo("GOMAXPROCS", "n", runtime.GOMAXPROCS(0))
LogDebug("GOMAXPROCS", "n", runtime.GOMAXPROCS(0))
}
4 changes: 2 additions & 2 deletions pkg/device/ws-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func wsServer(conn *websocket.Conn) {

// Add as active download link

LogInfo("Adding Downlink", "id", id)
LogDebug("Adding Downlink", "id", id)
downlinksAdd(id, link)

// Route incoming packets up to the destination device. Stop and
Expand All @@ -98,7 +98,7 @@ func wsServer(conn *websocket.Conn) {
deviceRouteUp(pkt.Dst, pkt)
}

LogInfo("Removing Downlink", "id", id)
LogDebug("Removing Downlink", "id", id)
downlinksRemove(id)

deviceOffline(id)
Expand Down

0 comments on commit 4ba3982

Please sign in to comment.