Skip to content

Commit

Permalink
Pull request 2287: 7315-fix-client-storage-panic
Browse files Browse the repository at this point in the history
Closes #7315.

Squashed commit of the following:

commit 94c8473
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Oct 3 19:09:23 2024 +0300

    all: upd chlog

commit 82b772b
Merge: e7f34cc 4919630
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Oct 3 19:00:53 2024 +0300

    Merge branch 'master' into 7315-fix-client-storage-panic

commit e7f34cc
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Oct 3 17:55:39 2024 +0300

    home: fix client storage panic
  • Loading branch information
schzhn committed Oct 4, 2024
1 parent 4919630 commit df09734
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ See also the [v0.107.54 GitHub milestone][ms-v0.107.54].
NOTE: Add new changes BELOW THIS COMMENT.
-->

### Fixed

- Missing runtime clients with information from the system hosts file on first
AdGuard Home start ([#7315]).

[#7315]: https://github.com/AdguardTeam/AdGuardHome/issues/7315

<!--
NOTE: Add new changes ABOVE THIS COMMENT.
-->
Expand Down
6 changes: 3 additions & 3 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func (clients *clientsContainer) Init(
// TODO(e.burkov): The option should probably be returned, since hosts file
// currently used not only for clients' information enrichment, but also in
// the filtering module and upstream addresses resolution.
var hosts client.HostsContainer = etcHosts
if !config.Clients.Sources.HostsFile {
hosts = nil
var hosts client.HostsContainer
if config.Clients.Sources.HostsFile && etcHosts != nil {
hosts = etcHosts
}

clients.storage, err = client.NewStorage(&client.StorageConfig{
Expand Down
16 changes: 8 additions & 8 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func setupContext(opts options) (err error) {
Context.tlsRoots = aghtls.SystemRootCAs()
Context.mux = http.NewServeMux()

if !opts.noEtcHosts {
err = setupHostsContainer()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
}
}

if Context.firstRun {
log.Info("This is the first time AdGuard Home is launched")
checkPermissions()
Expand All @@ -168,14 +176,6 @@ func setupContext(opts options) (err error) {
os.Exit(0)
}

if !opts.noEtcHosts {
err = setupHostsContainer()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
}
}

return nil
}

Expand Down

0 comments on commit df09734

Please sign in to comment.