libc/netdb: avoid unnecessary DNS notify if nameserver exists #17898
+3
−1
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.
If the nameserver already exists, return directly without calling dns_notify_nameserver to prevent cyclic notifications and high CPU usage.
Note: Please adhere to Contributing Guidelines.
Summary
When adding a nameserver via
dns_add_nameserver, if the server already exists in the configuration (return value is-EEXIST), the function previously jumped to theerroutlabel. This label executesdns_notify_nameserver, which sends a notification signal.In scenarios where multiple DNS updates occur or in master/slave synchronization contexts, this can lead to cyclic notifications and high CPU usage because the notification is sent even when no actual change was made (since the server already existed).
This patch modifies the behavior to return directly when the nameserver exists, skipping the unnecessary
dns_notify_nameservercall.Impact
Testing
dns_add_nameserveris called with an existing server address.dns_notify_nameserveris NOT called in this case.