Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/etc/hosts does not reload when changed #6711

Closed
4 tasks done
hwilson-dev opened this issue Feb 6, 2024 · 8 comments
Closed
4 tasks done

/etc/hosts does not reload when changed #6711

hwilson-dev opened this issue Feb 6, 2024 · 8 comments
Assignees
Milestone

Comments

@hwilson-dev
Copy link

Prerequisites

Platform (OS and CPU architecture)

Darwin (aka macOS), AMD64 (aka x86_64)

Installation

GitHub releases or script from README

Setup

On one machine

AdGuard Home version

0.107.44

Action

When I make a change the /etc/hosts, I expect it to show in the 'runtime clients' table and I expect the configured IP address to be returned when querying it.

Expected result

I expect the newly configured data to be show and used.

Actual result

The change in /etc/hosts does not become active until I restart the AdguardHome process.

By looking at the code and turning on debug, I see that an FSWatcher is instantiated for the file. But it never seem to recive any change notifications from the OS. I tried both macOS and Windows.

I cloned the fsnotify repo and ran their test application. It works as expected. So I suspect the issue is with the AdguardHome use of that code.

Please take a look.

Additional information and/or screenshots

No response

@hwilson-dev
Copy link
Author

hwilson-dev commented Feb 6, 2024

I was able to get it to work on macOS by using a Darwin specific defaultHostsPaths():

//go:build darwin

package aghnet

func defaultHostsPaths() (paths []string) {
        return []string{"private/etc/hosts"}
}

So I needed to use "private/" in front of "etc/hosts".

@hwilson-dev
Copy link
Author

I also needed this change in fswatcher.go:

-       return w.w.Add(filepath.Join("/", name))
+       return w.w.Add(filepath.Dir(filepath.Join("/", name)))

See the "Watching a file doesn't work well" comment in the README of the fsnotify repo.

@EugeneOne1
Copy link
Member

@hwilson-dev, hello and thanks for the report. What version of macOS do you use? It seems, the /etc directory is actually a symlink to the /private/etc directory. However, I can't reproduce the issue on my macOS 12.4 machine, trying to edit both /etc/hosts and /private/etc/hosts files. Did previous versions of AdGuard Home receive these notifications?

@EugeneOne1 EugeneOne1 added the waiting for data Waiting for users to provide more data. label Feb 7, 2024
@EugeneOne1 EugeneOne1 self-assigned this Feb 7, 2024
@EugeneOne1 EugeneOne1 added the needs investigation Needs to be reproduced reliably. label Feb 7, 2024
@hwilson-dev
Copy link
Author

@EugeneOne1 I'm on macOS 13.5.1. I started with v0.107.36 and am now on v0.107.44.

Without the changes mentioned above, it never worked for me on Windows or macOS.

@EugeneOne1
Copy link
Member

EugeneOne1 commented Feb 7, 2024

@hwilson-dev, do you happen to find out, which of these changes are required on Windows to fix the issue? AFAIK, at least, the file location isn't that tricky there.

@hwilson-dev
Copy link
Author

@EugeneOne1 The fswatcher.go change above:

-       return w.w.Add(filepath.Join("/", name))
+       return w.w.Add(filepath.Dir(filepath.Join("/", name)))

Made it work on Windows for me.

@EugeneOne1 EugeneOne1 added bug compatibility and removed needs investigation Needs to be reproduced reliably. waiting for data Waiting for users to provide more data. labels Feb 9, 2024
adguard pushed a commit that referenced this issue Feb 13, 2024
Updates #6711.

Squashed commit of the following:

commit 3ddfe80
Merge: 185957c d338451
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Feb 13 13:01:30 2024 +0300

    Merge branch 'master' into 6711-watch-hosts

commit 185957c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Feb 9 18:11:41 2024 +0300

    aghos: imp docs

commit 3afbbcb
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Feb 9 15:40:02 2024 +0300

    all: upd golibs, imp fswatcher
@EugeneOne1
Copy link
Member

@hwilson-dev, hello again. We've pushed the edge release that implements the suggested fixes, could you please check if it now tracks changes to the hosts file? Thanks for your participation.

@EugeneOne1
Copy link
Member

@hwilson-dev, we're going to close the issue for now, feel free to reopen it if the problem reoccurs.

@ainar-g ainar-g added this to the v0.107.46 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants