mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-06 16:02:55 +03:00
Pull request: 2552 rm context.TODO() instances
Merge in DNS/adguard-home from 2552-context to master
Closes #2552.
Squashed commit of the following:
commit 3d1cef33da529f4611869c4a0f2f294a3c8afcaf
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jan 26 19:28:23 2021 +0300
all: fix docs
commit d08c78cf4b96419b928e73c497768f40c9e47bc2
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jan 26 19:22:00 2021 +0300
all: doc changes
commit c2814f4d0025be74f38299e7e66e7c0193b6c15f
Merge: 100a1a09 44c7221a
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jan 26 19:12:55 2021 +0300
Merge branch 'master' into 2552-context
commit 100a1a0957bc22bfaccb1693e6b9b1c5cb53ed13
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jan 26 19:10:03 2021 +0300
home: imp docs, fix naming
commit 22717abe6c0e4c1016a53ff2fac1689d0762c462
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Jan 26 18:14:07 2021 +0300
home: improve code quality
commit 5c96f77a2b315e2c1ad4a11cc7a64f61bdba52a3
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Mon Jan 25 20:28:51 2021 +0300
home: add docs
commit 323fc013a57a5c06ec391003133b12f4eb2721cd
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Mon Jan 25 14:50:11 2021 +0300
home: rm context.TODO() instances
This commit is contained in:
parent
44c7221ae9
commit
c215b82004
9 changed files with 106 additions and 58 deletions
internal/home
|
@ -122,8 +122,9 @@ func WebCheckPortAvailable(port int) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// TLSConfigChanged - called when TLS configuration has changed
|
||||
func (web *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
|
||||
// TLSConfigChanged updates the TLS configuration and restarts the HTTPS server
|
||||
// if necessary.
|
||||
func (web *Web) TLSConfigChanged(ctx context.Context, tlsConf tlsConfigSettings) {
|
||||
log.Debug("Web: applying new TLS configuration")
|
||||
web.conf.PortHTTPS = tlsConf.PortHTTPS
|
||||
web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0)
|
||||
|
@ -143,7 +144,12 @@ func (web *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
|
|||
|
||||
web.httpsServer.cond.L.Lock()
|
||||
if web.httpsServer.server != nil {
|
||||
_ = web.httpsServer.server.Shutdown(context.TODO())
|
||||
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
|
||||
err = web.httpsServer.server.Shutdown(ctx)
|
||||
cancel()
|
||||
if err != nil {
|
||||
log.Debug("error while shutting down HTTP server: %s", err)
|
||||
}
|
||||
}
|
||||
web.httpsServer.enabled = enabled
|
||||
web.httpsServer.cert = cert
|
||||
|
@ -198,22 +204,28 @@ func (web *Web) Start() {
|
|||
}
|
||||
}
|
||||
|
||||
// Close - stop HTTP server, possibly waiting for all active connections to be closed
|
||||
func (web *Web) Close() {
|
||||
// Close gracefully shuts down the HTTP servers.
|
||||
func (web *Web) Close(ctx context.Context) {
|
||||
log.Info("Stopping HTTP server...")
|
||||
web.httpsServer.cond.L.Lock()
|
||||
web.httpsServer.shutdown = true
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
if web.httpsServer.server != nil {
|
||||
_ = web.httpsServer.server.Shutdown(context.TODO())
|
||||
}
|
||||
if web.httpServer != nil {
|
||||
_ = web.httpServer.Shutdown(context.TODO())
|
||||
}
|
||||
if web.httpServerBeta != nil {
|
||||
_ = web.httpServerBeta.Shutdown(context.TODO())
|
||||
|
||||
shut := func(srv *http.Server) {
|
||||
if srv == nil {
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(ctx); err != nil {
|
||||
log.Debug("error while shutting down HTTP server: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
shut(web.httpsServer.server)
|
||||
shut(web.httpServer)
|
||||
shut(web.httpServerBeta)
|
||||
|
||||
log.Info("Stopped HTTP server")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue