mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: locked mutex while blocked on I/O considered harmful (#935)
* fn: mutex while waiting I/O considered harmful *) Removed hold mutex while wait I/O cases these included possible disk I/O and network I/O. *) Error/Context Close/Shutdown semantics changed since the context timeout and comments were misleading. Close always waits for pending gRPC session to complete. Context usage here was merely 'wait up to x secs to report an error' which only logs the error anyway. Instead, the runner can log the error. And context still can be passed around perhaps for future opencensus instrumentation.
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fnproject/fn/api/common"
|
||||
"github.com/fnproject/fn/api/server"
|
||||
"github.com/fnproject/fn_go/client"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
@@ -24,11 +23,7 @@ import (
|
||||
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
func GetAPIURL() (string, *url.URL) {
|
||||
apiURL := os.Getenv("FN_API_URL")
|
||||
if apiURL == "" {
|
||||
apiURL = "http://localhost:8080"
|
||||
}
|
||||
|
||||
apiURL := getEnv("FN_API_URL", "http://localhost:8080")
|
||||
u, err := url.Parse(apiURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't parse API URL: %s error: %s", apiURL, err)
|
||||
@@ -79,12 +74,18 @@ func checkServer(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
|
||||
getServer.Do(func() {
|
||||
ctx := context.Background()
|
||||
|
||||
common.SetLogLevel("fatal")
|
||||
timeString := time.Now().Format("2006_01_02_15_04_05")
|
||||
dbURL := os.Getenv(server.EnvDBURL)
|
||||
tmpDir := os.TempDir()
|
||||
@@ -95,7 +96,12 @@ func startServer() {
|
||||
dbURL = fmt.Sprintf("sqlite3://%s", tmpDb)
|
||||
}
|
||||
|
||||
s = server.New(ctx, server.WithDBURL(dbURL), server.WithMQURL(mqURL), server.WithFullAgent())
|
||||
s = server.New(ctx,
|
||||
server.WithLogLevel(getEnv(server.EnvLogLevel, server.DefaultLogLevel)),
|
||||
server.WithDBURL(dbURL),
|
||||
server.WithMQURL(mqURL),
|
||||
server.WithFullAgent(),
|
||||
)
|
||||
|
||||
go func() {
|
||||
s.Start(ctx)
|
||||
|
||||
@@ -114,7 +114,7 @@ func SetUpAPINode(ctx context.Context) (*server.Server, error) {
|
||||
opts := make([]server.ServerOption, 0)
|
||||
opts = append(opts, server.WithWebPort(8085))
|
||||
opts = append(opts, server.WithType(nodeType))
|
||||
opts = append(opts, server.WithLogLevel(server.DefaultLogLevel))
|
||||
opts = append(opts, server.WithLogLevel(getEnv(server.EnvLogLevel, server.DefaultLogLevel)))
|
||||
opts = append(opts, server.WithLogDest(server.DefaultLogDest, "API"))
|
||||
opts = append(opts, server.WithDBURL(getEnv(server.EnvDBURL, defaultDB)))
|
||||
opts = append(opts, server.WithMQURL(getEnv(server.EnvMQURL, defaultMQ)))
|
||||
@@ -129,7 +129,7 @@ func SetUpLBNode(ctx context.Context) (*server.Server, error) {
|
||||
opts := make([]server.ServerOption, 0)
|
||||
opts = append(opts, server.WithWebPort(8081))
|
||||
opts = append(opts, server.WithType(nodeType))
|
||||
opts = append(opts, server.WithLogLevel(server.DefaultLogLevel))
|
||||
opts = append(opts, server.WithLogLevel(getEnv(server.EnvLogLevel, server.DefaultLogLevel)))
|
||||
opts = append(opts, server.WithLogDest(server.DefaultLogDest, "LB"))
|
||||
opts = append(opts, server.WithDBURL(""))
|
||||
opts = append(opts, server.WithMQURL(""))
|
||||
@@ -194,7 +194,7 @@ func SetUpPureRunnerNode(ctx context.Context, nodeNum int) (*server.Server, erro
|
||||
opts = append(opts, server.WithWebPort(8082+nodeNum))
|
||||
opts = append(opts, server.WithGRPCPort(9190+nodeNum))
|
||||
opts = append(opts, server.WithType(nodeType))
|
||||
opts = append(opts, server.WithLogLevel("debug"))
|
||||
opts = append(opts, server.WithLogLevel(getEnv(server.EnvLogLevel, server.DefaultLogLevel)))
|
||||
opts = append(opts, server.WithLogDest(server.DefaultLogDest, "PURE-RUNNER"))
|
||||
opts = append(opts, server.WithDBURL(""))
|
||||
opts = append(opts, server.WithMQURL(""))
|
||||
|
||||
Reference in New Issue
Block a user