Skip to content

Commit 780111b

Browse files
committed
Recover from Avahi setup failures
1 parent 0d5c023 commit 780111b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

comitup/mdns.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ def add_service(host: str, devindex: int, addr: str) -> None:
117117
# public functions
118118

119119

120-
def clear_entries() -> None:
120+
def clear_entries(emphatic=False) -> None:
121121
global group
122122

123123
if group and not group.IsEmpty():
124124
group.Reset()
125125

126+
if emphatic:
127+
group.Free()
128+
group = None
129+
126130
establish_group()
127131

128132

@@ -166,12 +170,19 @@ def add_hosts(hosts: List[str]) -> None:
166170
):
167171

168172
index = int_mapping[name]
169-
for host in hosts:
170-
log.debug("Add A record {}-{}-{}".format(host, index, addr))
171-
make_a_record(host, index, addr)
172173

173-
log.debug("Add service {}, {}, {}".format(host, index, addr))
174-
add_service(hosts[0], index, addr)
174+
try:
175+
for host in hosts:
176+
log.debug(
177+
"Add A record {}-{}-{}".format(host, index, addr)
178+
)
179+
make_a_record(host, index, addr)
180+
181+
log.debug("Add service {}, {}, {}".format(host, index, addr))
182+
add_service(hosts[0], index, addr)
183+
except Exception:
184+
log.error("Exception encountered adding avahi record")
185+
clear_entries(emphatic=True)
175186

176187
entries = True
177188

0 commit comments

Comments
 (0)