Skip to content

Commit

Permalink
Stream stderr to logs for streaming fork mode
Browse files Browse the repository at this point in the history
This mode is not expected to be used by any customers in
production, however we received a message from a customer who
had decided to use this mode.

They reported not being able to log to stderr, I was able to
reproduce the problem and have added bindLoggingPipe to
stderr as per the other modes in the of-watchdog.

After testing with a simple Python program, the logging is
now available.

We only recommend HTTP mode for production use.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed May 31, 2023
1 parent ea3bcc4 commit a5324bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion executor/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

// bindLoggingPipe spawns a goroutine for passing through logging of the given output pipe.
//
func bindLoggingPipe(name string, pipe io.Reader, output io.Writer, logPrefix bool, maxBufferSize int) {
log.Printf("Started logging: %s from function.", name)

Expand Down
9 changes: 7 additions & 2 deletions executor/serializing_fork_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"

units "github.com/docker/go-units"

Expand All @@ -21,8 +22,9 @@ import (

// SerializingForkFunctionRunner forks a process for each invocation
type SerializingForkFunctionRunner struct {
ExecTimeout time.Duration
LogPrefix bool
ExecTimeout time.Duration
LogPrefix bool
LogBufferSize int
}

// Run run a fork for each invocation
Expand Down Expand Up @@ -99,11 +101,14 @@ func serializeFunction(req FunctionRequest, f *SerializingForkFunctionRunner) (*

stdout, _ := cmd.StdoutPipe()
stdin, _ := cmd.StdinPipe()
stderr, _ := cmd.StderrPipe()

if err := cmd.Start(); err != nil {
return nil, err
}

bindLoggingPipe("stderr", stderr, os.Stderr, f.LogPrefix, f.LogBufferSize)

functionRes, errors := pipeToProcess(stdin, stdout, &data)
if len(errors) > 0 {
return nil, errors[0]
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ func createLockFile() (string, error) {

func makeSerializingForkRequestHandler(watchdogConfig config.WatchdogConfig, logPrefix bool) func(http.ResponseWriter, *http.Request) {
functionInvoker := executor.SerializingForkFunctionRunner{
ExecTimeout: watchdogConfig.ExecTimeout,
LogPrefix: logPrefix,
ExecTimeout: watchdogConfig.ExecTimeout,
LogPrefix: logPrefix,
LogBufferSize: watchdogConfig.LogBufferSize,
}

return func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit a5324bf

Please sign in to comment.