Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/envd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -179,6 +180,20 @@ func run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Bind the listener before any blocking initializer so the TCP port is
// reachable from process start. Incoming connections are queued in the
// kernel's accept backlog; nothing is dispatched until s.Serve(ln) below.
// Without this, a slow or hanging initializer (e.g. writeCgroupProp under
// memory pressure) produces a window where the process is alive but the port
// returns ECONNREFUSED — indistinguishable from a crashed envd to any
// TCP-based health check or orchestrator readiness probe.
ln, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
if err != nil {
return fmt.Errorf("bind envd listener: %w", err)
}
defer ln.Close()
fmt.Fprintf(os.Stderr, "envd: HTTP listener bound on :%d\n", port)

if err := os.MkdirAll(host.E2BRunDir, 0o755); err != nil {
fmt.Fprintf(os.Stderr, "error creating E2B run directory: %v\n", err)
}
Expand Down Expand Up @@ -207,7 +222,9 @@ func run() error {
fsLogger := l.With().Str("logger", "filesystem").Logger()
filesystemService := filesystemRpc.Handle(m, &fsLogger, defaults)

fmt.Fprintf(os.Stderr, "envd startup: creating cgroup manager\n")
cgroupManager := createCgroupManager()
fmt.Fprintf(os.Stderr, "envd startup: cgroup manager ready\n")
defer func() {
err := cgroupManager.Close()
if err != nil {
Expand Down Expand Up @@ -445,7 +462,7 @@ func run() error {
}
})

err := s.ListenAndServe()
err = s.Serve(ln)
// Signal goroutines to stop before deferred cleanup closes their resources.
// TODO: shutdown synchronization needs to be revisited.
cancel()
Expand Down
2 changes: 1 addition & 1 deletion packages/envd/pkg/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package pkg

const Version = "0.7.0" // x-release-please-version
const Version = "0.7.1" // x-release-please-version