Fix(entryGroups): Prevent deadlock and improve robustness #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The service could previously enter a stalled state due to a deadlock in the
entryGroups
struct, which manages Avahi mDNS registrations.The deadlock occurred if
avahiServer.EntryGroupNew()
failed. In this scenario, thecommit
function (called viadefer
inhandleContainer
) would attempt to operate on a non-existent or nil entry group withine.groups[containerID]
. This would cause a panic inside thecommit
function beforee.mutex.Unlock()
was called, leaving the mutex permanently locked. Subsequent calls tohandleContainer
would then block indefinitely on this mutex.This commit addresses the issue by:
commit
function inentryGroups.get
panic-safe:e.mutex.Unlock()
to ensure the mutex is alwaysreleased when
commit
exits, regardless of internal errors orpanics.
get
) indicating whether the Avahi groupwas successfully retrieved or created. If not, it avoids operations
on the group, preventing the panic.
EntryGroupNew()
fails, the failed group is notadded to the internal map, and
get()
returns the error appropriately.Additionally, this change includes:
entry_groups.go
,dns.go
, andcontainer.go
to aid in future diagnostics.entryGroups.get
covering success,EntryGroupNew
failure, and different logic paths within thecommit
function.The investigation into Avahi call timeouts revealed that while the underlying
godbus
library supports contexts,go-avahi
does not currently expose this for per-call timeouts. This is noted for potential future enhancement if Avahi calls themselves prove to be a source of prolonged blocking.