dhcp4d: only publish to MQTT when channel is ready to prevent deadlocks

This commit is contained in:
Michael Stapelberg 2020-12-31 16:42:12 +01:00
parent c3c531931c
commit 5f25043b94

View File

@ -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")