Skip to content

infinite loop on bus loss #21

@nick-owens-eero

Description

@nick-owens-eero

hi,

it seems that the avahi Server signal handler in https://github.com/holoplot/go-avahi/blob/master/server.go#L50 will check for the closure of the dbus Signal channel, but if it is closed, it simply continues the loop. the loop isn't cleaned up until an explicit Server.Close().

this leads to the inner signal handler spinning tightly on select if one did not call Close on dbus connection loss. how are users of this library expected to handle bus loss? for now my best guess is that a caller needs to register their own Signal channel to the dbus Conn and wait for it to close, and then Close the avahi Server. is that right? this seems like a big footgun.

in the following example we spin forever inside of ServerNew's anonymous function, unless you uncomment the two lines in the select{} with the explicit Server.Close() triggered by the dbus.Signal channel closure.

package main

import (
	"log"

	"github.com/godbus/dbus/v5"
	"github.com/holoplot/go-avahi"
)

func main() {
	conn, err := dbus.SystemBus()
	if err != nil {
		log.Fatalf("Cannot get system bus: %v", err)
	}

	server, err := avahi.ServerNew(conn)
	if err != nil {
		log.Fatalf("Avahi new failed: %v", err)
	}

	host, err := server.GetHostName()
	if err != nil {
		log.Fatalf("GetHostName() failed: %v", err)
	}
	log.Println("GetHostName()", host)

	// Register a DBus signal handler
	sig := make(chan *dbus.Signal)
	conn.Signal(sig)

	// Terminate the dbus connection, or otherwise simulate loss of the bus (e.g., dbus restarted).
	log.Println("Conn.Close():", conn.Close())

	doit := true
	for doit {
		select {
		case _, ok := <-sig:
			if !ok {
				//server.Close()
				//doit = false
			}
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions