Skip to content

Commit

Permalink
Pull request 1977: 6100-fix-query-log
Browse files Browse the repository at this point in the history
Updates #6100.

Squashed commit of the following:

commit f8a37b4
Author: Stanislav Chzhen <[email protected]>
Date:   Mon Aug 28 14:08:41 2023 +0300

    home: imp code

commit 2dd357f
Author: Stanislav Chzhen <[email protected]>
Date:   Fri Aug 25 19:35:42 2023 +0300

    all: imp docs

commit 369f178
Author: Stanislav Chzhen <[email protected]>
Date:   Fri Aug 25 19:26:14 2023 +0300

    all: upd chlog

commit c07d80e
Author: Stanislav Chzhen <[email protected]>
Date:   Fri Aug 25 16:22:58 2023 +0300

    home: fix more

commit 3872806
Author: Stanislav Chzhen <[email protected]>
Date:   Thu Aug 24 15:35:22 2023 +0300

    home: fix query log
  • Loading branch information
schzhn committed Aug 28, 2023
1 parent 2c9dcc1 commit 59a4a00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ In this release, the schema version has changed from 24 to 25.

### Fixed

- Missing query log entries and statistics on service restart ([#6100]).
- Occasional DNS-over-QUIC and DNS-over-HTTP/3 errors ([#6133]).
- Legacy DNS rewrites containing IPv4-mapped IPv6 addresses are now matching the
`AAAA` requests, not `A` ([#6050]).
Expand All @@ -84,6 +85,7 @@ In this release, the schema version has changed from 24 to 25.
[#6050]: https://github.com/AdguardTeam/AdGuardHome/issues/6050
[#6053]: https://github.com/AdguardTeam/AdGuardHome/issues/6053
[#6093]: https://github.com/AdguardTeam/AdGuardHome/issues/6093
[#6100]: https://github.com/AdguardTeam/AdGuardHome/issues/6100
[#6122]: https://github.com/AdguardTeam/AdGuardHome/issues/6122
[#6133]: https://github.com/AdguardTeam/AdGuardHome/issues/6133

Expand Down
4 changes: 0 additions & 4 deletions internal/home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,10 @@ func closeDNSServer() {
if err != nil {
log.Debug("closing stats: %s", err)
}

// TODO(e.burkov): Find out if it's safe.
Context.stats = nil
}

if Context.queryLog != nil {
Context.queryLog.Close()
Context.queryLog = nil
}

log.Debug("all dns modules are closed")
Expand Down
15 changes: 9 additions & 6 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ func Main(clientBuildFS fs.FS) {
// package flag.
opts := loadCmdLineOpts()

done := make(chan struct{})

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)

go func() {
for {
sig := <-signals
Expand All @@ -112,19 +115,19 @@ func Main(clientBuildFS fs.FS) {
default:
cleanup(context.Background())
cleanupAlways()
os.Exit(0)
close(done)
}
}
}()

if opts.serviceControlAction != "" {
handleServiceControlAction(opts, clientBuildFS, signals)
handleServiceControlAction(opts, clientBuildFS, done)

return
}

// run the protection
run(opts, clientBuildFS)
run(opts, clientBuildFS, done)
}

// setupContext initializes [Context] fields. It also reads and upgrades
Expand Down Expand Up @@ -504,7 +507,7 @@ func fatalOnError(err error) {
}

// run configures and starts AdGuard Home.
func run(opts options, clientBuildFS fs.FS) {
func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
// Configure config filename.
initConfigFilename(opts)

Expand Down Expand Up @@ -609,8 +612,8 @@ func run(opts options, clientBuildFS fs.FS) {

Context.web.start()

// Wait indefinitely for other goroutines to complete their job.
select {}
// Wait for other goroutines to complete their job.
<-done
}

// initUsers initializes context auth module. Clears config users field.
Expand Down
17 changes: 7 additions & 10 deletions internal/home/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// daemon.
type program struct {
clientBuildFS fs.FS
signals chan os.Signal
done chan struct{}
opts options
}

Expand All @@ -46,19 +46,16 @@ func (p *program) Start(_ service.Service) (err error) {
args := p.opts
args.runningAsService = true

go run(args, p.clientBuildFS)
go run(args, p.clientBuildFS, p.done)

return nil
}

// Stop implements service.Interface interface for *program.
func (p *program) Stop(_ service.Service) (err error) {
select {
case p.signals <- syscall.SIGINT:
// Go on.
default:
// Stop should not block.
}
log.Info("service: stopping: waiting for cleanup")

<-p.done

return nil
}
Expand Down Expand Up @@ -198,7 +195,7 @@ func restartService() (err error) {
// - run: This is a special command that is not supposed to be used directly
// it is specified when we register a service, and it indicates to the app
// that it is being run as a service/daemon.
func handleServiceControlAction(opts options, clientBuildFS fs.FS, signals chan os.Signal) {
func handleServiceControlAction(opts options, clientBuildFS fs.FS, done chan struct{}) {
// Call chooseSystem explicitly to introduce OpenBSD support for service
// package. It's a noop for other GOOS values.
chooseSystem()
Expand Down Expand Up @@ -232,7 +229,7 @@ func handleServiceControlAction(opts options, clientBuildFS fs.FS, signals chan

s, err := service.New(&program{
clientBuildFS: clientBuildFS,
signals: signals,
done: done,
opts: runOpts,
}, svcConfig)
if err != nil {
Expand Down

0 comments on commit 59a4a00

Please sign in to comment.