prefork.go — fiber Source File
Architecture documentation for prefork.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8f3667ad_bf3e_1448_af92_703572fb17e0["prefork.go"] 633f63d7_c731_5dad_c6ed_c9824feba192["tls"] 8f3667ad_bf3e_1448_af92_703572fb17e0 --> 633f63d7_c731_5dad_c6ed_c9824feba192 style 8f3667ad_bf3e_1448_af92_703572fb17e0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package fiber
import (
"crypto/tls"
"errors"
"fmt"
"net"
"os"
"os/exec"
"runtime"
"sync/atomic"
"time"
"github.com/valyala/fasthttp/reuseport"
"github.com/gofiber/fiber/v3/log"
)
const (
envPreforkChildKey = "FIBER_PREFORK_CHILD"
envPreforkChildVal = "1"
sleepDuration = 100 * time.Millisecond
windowsOS = "windows"
)
var (
testPreforkMaster = false
testOnPrefork = false
)
// IsChild determines if the current process is a child of Prefork
func IsChild() bool {
return os.Getenv(envPreforkChildKey) == envPreforkChildVal
}
// prefork manages child processes to make use of the OS REUSEPORT or REUSEADDR feature
func (app *App) prefork(addr string, tlsConfig *tls.Config, cfg *ListenConfig) error {
if cfg == nil {
cfg = &ListenConfig{}
}
var ln net.Listener
var err error
// 👶 child process 👶
if IsChild() {
// use 1 cpu core per child process
runtime.GOMAXPROCS(1)
// Linux will use SO_REUSEPORT and Windows falls back to SO_REUSEADDR
// Only tcp4 or tcp6 is supported when preforking, both are not supported
if ln, err = reuseport.Listen(cfg.ListenerNetwork, addr); err != nil {
if !cfg.DisableStartupMessage {
time.Sleep(sleepDuration) // avoid colliding with startup message
}
return fmt.Errorf("prefork: %w", err)
}
// wrap a tls config around the listener if provided
if tlsConfig != nil {
ln = tls.NewListener(ln, tlsConfig)
}
// ... (133 more lines)
Domain
Subdomains
Functions
Dependencies
- tls
Source
Frequently Asked Questions
What does prefork.go do?
prefork.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Routing subdomain.
What functions are defined in prefork.go?
prefork.go defines 3 function(s): IsChild, dummyCmd, watchMaster.
What does prefork.go depend on?
prefork.go imports 1 module(s): tls.
Where is prefork.go in the architecture?
prefork.go is located at prefork.go (domain: FiberCore, subdomain: Routing).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free