Fix race condition in fetcher readyness check (#2101)
Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
+12
-12
@@ -24,6 +24,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
|
||||
"contrib.go.opencensus.io/exporter/jaeger"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
@@ -33,6 +34,10 @@ import (
|
||||
"github.com/fission/fission/pkg/fetcher"
|
||||
)
|
||||
|
||||
var (
|
||||
readyToServe uint32
|
||||
)
|
||||
|
||||
func registerTraceExporter(collectorEndpoint string) error {
|
||||
if collectorEndpoint == "" {
|
||||
return nil
|
||||
@@ -80,17 +85,17 @@ func Run(logger *zap.Logger) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := registerTraceExporter(*collectorEndpoint); err != nil {
|
||||
logger.Fatal("could not register trace exporter", zap.Error(err), zap.String("collector_endpoint", *collectorEndpoint))
|
||||
}
|
||||
go func() {
|
||||
if err := registerTraceExporter(*collectorEndpoint); err != nil {
|
||||
logger.Fatal("could not register trace exporter", zap.Error(err), zap.String("collector_endpoint", *collectorEndpoint))
|
||||
}
|
||||
}()
|
||||
|
||||
f, err := fetcher.MakeFetcher(logger, dir, *secretDir, *configDir)
|
||||
if err != nil {
|
||||
logger.Fatal("error making fetcher", zap.Error(err))
|
||||
}
|
||||
|
||||
readyToServe := false
|
||||
|
||||
// do specialization in other goroutine to prevent blocking in newdeploy
|
||||
go func() {
|
||||
if *specializeOnStart {
|
||||
@@ -106,9 +111,8 @@ func Run(logger *zap.Logger) {
|
||||
if err != nil {
|
||||
logger.Fatal("error specializing function pod", zap.Error(err))
|
||||
}
|
||||
|
||||
readyToServe = true
|
||||
}
|
||||
atomic.StoreUint32(&readyToServe, 1)
|
||||
}()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
@@ -120,7 +124,7 @@ func Run(logger *zap.Logger) {
|
||||
mux.HandleFunc("/wsevent/end", f.WsEndHandler)
|
||||
|
||||
readinessHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
if !*specializeOnStart || readyToServe {
|
||||
if atomic.LoadUint32(&readyToServe) == 1 {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
@@ -132,10 +136,6 @@ func Run(logger *zap.Logger) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
// For backward compatibility
|
||||
// TODO: remove this path in future
|
||||
mux.HandleFunc("/readniess-healthz", readinessHandler)
|
||||
|
||||
logger.Info("fetcher ready to receive requests")
|
||||
err = http.ListenAndServe(":8000", &ochttp.Handler{
|
||||
Handler: mux,
|
||||
|
||||
Reference in New Issue
Block a user