mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-04 11:14:42 +08:00
core: Major refactor for graceful restarts; numerous fixes
Merged config and app packages into one called caddy. Abstracted away caddy startup functionality making it easier to embed Caddy in any Go application and use it as a library. Graceful restart (should) now ensure child starts properly. Now piping a gob bundle to child process so that the child can match up inherited listeners to server address. Much cleanup still to do.
This commit is contained in:
@ -65,6 +65,12 @@ type gracefulConn struct {
|
||||
|
||||
// Close closes c's underlying connection while updating the wg count.
|
||||
func (c gracefulConn) Close() error {
|
||||
err := c.Conn.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// close can fail on http2 connections (as of Oct. 2015, before http2 in std lib)
|
||||
// so don't decrement count unless close succeeds
|
||||
c.httpWg.Done()
|
||||
return c.Conn.Close()
|
||||
return nil
|
||||
}
|
||||
|
@ -59,14 +59,13 @@ func New(addr string, configs []Config) (*Server, error) {
|
||||
tls: tls,
|
||||
vhosts: make(map[string]virtualHost),
|
||||
}
|
||||
s.Handler = s // TODO: this is weird
|
||||
s.Handler = s // this is weird, but whatever
|
||||
|
||||
// We have to bound our wg with one increment
|
||||
// to prevent a "race condition" that is hard-coded
|
||||
// into sync.WaitGroup.Wait() - basically, an add
|
||||
// with a positive delta must be guaranteed to
|
||||
// occur before Wait() is called on the wg.
|
||||
fmt.Println("+1 (new)")
|
||||
s.httpWg.Add(1)
|
||||
|
||||
// Set up each virtualhost
|
||||
@ -169,11 +168,6 @@ func (s *Server) setup() error {
|
||||
// by the Go Authors. It has been modified to support multiple certificate/key pairs,
|
||||
// client authentication, and our custom Server type.
|
||||
func serveTLSWithSNI(s *Server, ln net.Listener, tlsConfigs []TLSConfig) error {
|
||||
addr := s.Server.Addr
|
||||
if addr == "" {
|
||||
addr = ":https"
|
||||
}
|
||||
|
||||
config := cloneTLSConfig(s.TLSConfig)
|
||||
if config.NextProtos == nil {
|
||||
config.NextProtos = []string{"http/1.1"}
|
||||
@ -267,7 +261,7 @@ func (s *Server) ListenerFd() uintptr {
|
||||
// (configuration and middleware stack) will handle the request.
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Sleeping")
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(5 * time.Second) // TODO: Temporarily making requests hang so we can test graceful restart
|
||||
fmt.Println("Unblocking")
|
||||
defer func() {
|
||||
// In case the user doesn't enable error middleware, we still
|
||||
|
Reference in New Issue
Block a user