AlexxIT/go2rtc · error

err.Error()

Error message

err.Error()

What it means

apiDvrip handles the dvrip discovery API endpoint: it calls discover(), which broadcasts on UDP port 34569 to find Dahua-style IP cameras. If discovery returns an error (typically failure to bind or send/receive on the UDP socket), err.Error() is returned with HTTP 500. The library surfaces the raw socket error so network problems are visible.

Solutions

  1. Check the error text in the 500 response — it names the failing socket operation
  2. Ensure the host has an active network interface and the firewall allows outbound UDP broadcasts (port 34569)
  3. If in Docker, use host networking (--network host) so UDP broadcasts reach the LAN
  4. Verify nothing else is bound to UDP port 34569 (ss -ulpn | grep 34569)
  5. Retry discovery; transient interface-down states (Wi-Fi reconnect) can cause failures

Example fix

// before
docker run -p 1984:1984 go2rtc
// after
docker run --network host go2rtc
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side precheck: is UDP broadcast viable on this interface?
iface, err := net.InterfaceByName("eth0")
if err != nil || (iface.Flags&net.FlagUp) == 0 || (iface.Flags&net.FlagBroadcast) == 0 {
    // discovery will likely fail; fix network first
}

Try / catch

resp, err := http.Get(baseURL + "/api/dvrip")
if err == nil && resp.StatusCode == http.StatusInternalServerError {
    b, _ := io.ReadAll(resp.Body)
    log.Printf("dvrip discovery failed: %s — retrying with host network/firewall fix", string(b))
}

Prevention

When it happens

Trigger: GET on the dvrip API when the UDP broadcast fails: no network interface can send the broadcast packet, binding to port 34569 fails (port in use or permission denied), or the socket operations return an OS error.

Common situations: Running inside a Docker bridge network where UDP broadcasts do not propagate, firewall rules blocking outbound UDP broadcast, missing SO_BROADCAST privileges, or running on a host with no active network interface.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/fa27e75bba259bf9. Report an issue: GitHub.

Appendix: source

Thrown at internal/dvrip/dvrip.go:28

	"github.com/AlexxIT/go2rtc/internal/api"
	"github.com/AlexxIT/go2rtc/internal/streams"
	"github.com/AlexxIT/go2rtc/pkg/dvrip"
)

func Init() {
	streams.HandleFunc("dvrip", dvrip.Dial)

	// DVRIP client autodiscovery
	api.HandleFunc("api/dvrip", apiDvrip)
}

const Port = 34569 // UDP port number for dvrip discovery

func apiDvrip(w http.ResponseWriter, r *http.Request) {
	items, err := discover()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	api.ResponseSources(w, items)
}

func discover() ([]*api.Source, error) {
	addr := &net.UDPAddr{
		Port: Port,
		IP:   net.IP{239, 255, 255, 250},
	}

	conn, err := net.ListenUDP("udp4", addr)
	if err != nil {
		return nil, err
	}

	defer conn.Close()

View on GitHub (pinned to c245815e75)