1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 06:01:29 +00:00

Merge pull request #1414 from FlamingTree/develop

bugfix: graceful failed when both enable http and https
This commit is contained in:
astaxie 2015-11-04 23:27:27 +08:00
commit e3120226fa

13
app.go
View File

@ -89,6 +89,7 @@ func (app *App) Run() {
} }
} else { } else {
if Graceful { if Graceful {
httpsAddr := addr
app.Server.Addr = addr app.Server.Addr = addr
app.Server.Handler = app.Handlers app.Server.Handler = app.Handlers
app.Server.ReadTimeout = time.Duration(HTTPServerTimeOut) * time.Second app.Server.ReadTimeout = time.Duration(HTTPServerTimeOut) * time.Second
@ -97,11 +98,12 @@ func (app *App) Run() {
go func() { go func() {
time.Sleep(20 * time.Microsecond) time.Sleep(20 * time.Microsecond)
if HTTPSPort != 0 { if HTTPSPort != 0 {
addr = fmt.Sprintf("%s:%d", HTTPAddr, HTTPSPort) httpsAddr = fmt.Sprintf("%s:%d", HTTPAddr, HTTPSPort)
app.Server.Addr = addr app.Server.Addr = httpsAddr
} }
server := grace.NewServer(addr, app.Handlers) server := grace.NewServer(httpsAddr, app.Handlers)
server.Server = app.Server server.Server.ReadTimeout = app.Server.ReadTimeout
server.Server.WriteTimeout = app.Server.WriteTimeout
err := server.ListenAndServeTLS(HTTPCertFile, HTTPKeyFile) err := server.ListenAndServeTLS(HTTPCertFile, HTTPKeyFile)
if err != nil { if err != nil {
BeeLogger.Critical("ListenAndServeTLS: ", err, fmt.Sprintf("%d", os.Getpid())) BeeLogger.Critical("ListenAndServeTLS: ", err, fmt.Sprintf("%d", os.Getpid()))
@ -113,7 +115,8 @@ func (app *App) Run() {
if EnableHTTPListen { if EnableHTTPListen {
go func() { go func() {
server := grace.NewServer(addr, app.Handlers) server := grace.NewServer(addr, app.Handlers)
server.Server = app.Server server.Server.ReadTimeout = app.Server.ReadTimeout
server.Server.WriteTimeout = app.Server.WriteTimeout
if ListenTCP4 && HTTPAddr == "" { if ListenTCP4 && HTTPAddr == "" {
server.Network = "tcp4" server.Network = "tcp4"
} }