From 5f25043b9442b7b92488f6dbe98dd02c7f8b46ae Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 31 Dec 2020 16:42:12 +0100 Subject: [PATCH] dhcp4d: only publish to MQTT when channel is ready to prevent deadlocks --- cmd/dhcp4d/dhcp4d.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/dhcp4d/dhcp4d.go b/cmd/dhcp4d/dhcp4d.go index 5c48e6f..5a9b9e1 100644 --- a/cmd/dhcp4d/dhcp4d.go +++ b/cmd/dhcp4d/dhcp4d.go @@ -420,10 +420,16 @@ func newSrv(permDir string) (*srv, error) { if identifier == "" { identifier = latest.HardwareAddr } - mayqtt <- PublishRequest{ + select { + case mayqtt <- PublishRequest{ Topic: "router7/dhcp4d/lease/" + identifier, Retained: true, Payload: leaseJSON, + }: + default: + // Channel not ready? skip publishing this lease (best-effort). + // This is an easy way of breaking circular dependencies between + // MQTT broker and DHCP server, and avoiding deadlocks. } } conn, err := conn.NewUDP4BoundListener(*iface, ":67")