Skip to content

Commit

Permalink
Merge pull request #2 from depot/feat/report-alive
Browse files Browse the repository at this point in the history
feat: report version number as ready signal
  • Loading branch information
goller authored May 23, 2023
2 parents bab1b4f + eea7ff7 commit 39001ea
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"os/signal"
Expand All @@ -21,6 +22,8 @@ import (
"sync/atomic"
)

const Version = 3

func main() {
rawConfig, err := base64.StdEncoding.DecodeString(os.Getenv("CONFIG"))
if err != nil {
Expand All @@ -38,6 +41,12 @@ func main() {
log.Fatal(err)
}

// Bind to port before sending the version-alive byte.
ln, err := net.Listen("tcp", ":8888")
if err != nil {
log.Fatal(err)
}

transport := NewTransport(os.Stdin, os.Stdout)
go transport.Run()

Expand Down Expand Up @@ -68,8 +77,14 @@ func main() {
close(idleConnsClosed)
}()

if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Fatalf("HTTP server ListenAndServe: %v", err)
// Report that network and transport are ready.
_, err = os.Stderr.Write([]byte{Version})
if err != nil {
log.Fatal(err)
}

if err := srv.Serve(ln); err != http.ErrServerClosed {
log.Fatalf("HTTP server: %v", err)
}

<-idleConnsClosed
Expand Down

0 comments on commit 39001ea

Please sign in to comment.