Skip to content

Commit

Permalink
Potential fix by not using http.Handle("/", …) in favor of `http.Se…
Browse files Browse the repository at this point in the history
…rve`

We use custom listeners, and mix of various routers (which depend on
configuration options). `http.Handle` use default Go listener, which may
not work well with tyk listener dynamic nature. Using `http.Server`
should fix TykTechnologies#531 and similar issues.
  • Loading branch information
buger committed Mar 9, 2017
1 parent fd88dae commit 6dbf9fc
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,19 +1321,20 @@ func listen(l, controlListener net.Listener, err error) {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Printf("Gateway started (%v)", VERSION)

if !RPC_EmergencyMode {
http.Handle("/", mainRouter)
}
go http.Serve(l, nil)
go http.Serve(l, mainRouter)

if controlListener != nil {
go http.Serve(controlListener, controlRouter)
if controlListener != nil {
go http.Serve(controlListener, controlRouter)
}
} else {
go http.Serve(l, nil)
}

displayConfig()
}

} else {

// handle dashboard registration and nonces if available
nonce := os.Getenv("TYK_SERVICE_NONCE")
nodeID := os.Getenv("TYK_SERVICE_NODEID")
Expand Down Expand Up @@ -1401,8 +1402,12 @@ func listen(l, controlListener net.Listener, err error) {
"prefix": "main",
}).Printf("Gateway resumed (%v)", VERSION)
displayConfig()
http.Handle("/", mainRouter)
go http.Serve(l, nil)

go http.Serve(l, mainRouter)

if controlListener != nil {
go http.Serve(controlListener, controlRouter)
}
}

log.WithFields(logrus.Fields{
Expand Down

0 comments on commit 6dbf9fc

Please sign in to comment.