Skip to content

Commit

Permalink
fix: port already in use investigation (#1746)
Browse files Browse the repository at this point in the history
Fixes: #1722

Port was in the random local range of ports which was sometimes being
used when trying to bind.

The solution is to use a port outside the random range (<32767), so I
picked 15432 instead of 54320.
  • Loading branch information
gak authored Jun 12, 2024
1 parent 16646b6 commit b7f7554
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 36 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,26 @@ jobs:
name: Test Go
runs-on: ubuntu-latest
steps:
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Docker Compose
run: docker compose up -d --wait
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Test
run: go-test-annotate
test-readme:
name: Test README
runs-on: ubuntu-latest
steps:
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Docker Compose
run: docker compose up -d --wait
- name: Test README
Expand All @@ -50,20 +40,14 @@ jobs:
name: SQL
runs-on: ubuntu-latest
steps:
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Docker Compose
run: docker compose up -d --wait
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Initialise database
run: just init-db
- name: Vet SQL
Expand Down Expand Up @@ -187,8 +171,6 @@ jobs:
fail-fast: false
matrix: ${{fromJson(needs.integration-shard.outputs.matrix)}}
steps:
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Checkout code
uses: actions/checkout@v4
- name: Init Hermit
Expand All @@ -197,16 +179,10 @@ jobs:
cache: true
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Docker Compose
run: docker compose up -d --wait
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Create DB
run: just init-db
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Download Go Modules
run: go mod download
- name: Run ${{ matrix.test }}
Expand All @@ -218,7 +194,5 @@ jobs:
needs: [integration-run]
runs-on: ubuntu-latest
steps:
- name: Show all TCP ports listening
run: sudo netstat -lpnt
- name: Ok
run: echo "Integration tests passed"
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ build +tools: build-protos build-zips build-frontend
build-backend:
just build ftl ftl-controller ftl-runner

export DATABASE_URL := "postgres://postgres:secret@localhost:54320/ftl?sslmode=disable"
export DATABASE_URL := "postgres://postgres:secret@localhost:15432/ftl?sslmode=disable"

# Explicitly initialise the database
init-db:
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Config struct {
Bind *url.URL `help:"Socket to bind to." default:"http://localhost:8892" env:"FTL_CONTROLLER_BIND"`
IngressBind *url.URL `help:"Socket to bind to for ingress." default:"http://localhost:8891" env:"FTL_CONTROLLER_INGRESS_BIND"`
Key model.ControllerKey `help:"Controller key (auto)." placeholder:"KEY"`
DSN string `help:"DAL DSN." default:"postgres://localhost:54320/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_CONTROLLER_DSN"`
DSN string `help:"DAL DSN." default:"postgres://localhost:15432/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_CONTROLLER_DSN"`
Advertise *url.URL `help:"Endpoint the Controller should advertise (must be unique across the cluster, defaults to --bind if omitted)." env:"FTL_CONTROLLER_ADVERTISE"`
ConsoleURL *url.URL `help:"The public URL of the console (for CORS)." env:"FTL_CONTROLLER_CONSOLE_URL"`
ContentTime time.Time `help:"Time to use for console resource timestamps." default:"${timestamp=1970-01-01T00:00:00Z}"`
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/sql/sqltest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func OpenForTesting(ctx context.Context, t testing.TB) *pgxpool.Pool {
assert.NoError(t, err)
t.Cleanup(func() { _ = release() })

testDSN := "postgres://localhost:54320/ftl-test?user=postgres&password=secret&sslmode=disable"
testDSN := "postgres://localhost:15432/ftl-test?user=postgres&password=secret&sslmode=disable"
conn, err := databasetesting.CreateForDevel(ctx, testDSN, true)
assert.NoError(t, err)
return conn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ ftl-min-version = ""
[modules]
[modules.database]
[modules.database.secrets]
FTL_DSN_DATABASE_TESTDB = "inline://InBvc3RncmVzOi8vcG9zdGdyZXM6c2VjcmV0QGxvY2FsaG9zdDo1NDMyMC90ZXN0ZGI_c3NsbW9kZT1kaXNhYmxlIg"
FTL_DSN_DATABASE_TESTDB = "inline://InBvc3RncmVzOi8vcG9zdGdyZXM6c2VjcmV0QGxvY2FsaG9zdDoxNTQzMi90ZXN0ZGI_c3NsbW9kZT1kaXNhYmxlIg"

[commands]
2 changes: 1 addition & 1 deletion cmd/ftl-initdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var cli struct {
log.Config
Recreate bool `help:"Drop and recreate the database."`
DSN string `help:"Postgres DSN." default:"postgres://localhost:54320/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_CONTROLLER_DSN"`
DSN string `help:"Postgres DSN." default:"postgres://localhost:15432/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_CONTROLLER_DSN"`
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ftl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
type serveCmd struct {
Bind *url.URL `help:"Starting endpoint to bind to and advertise to. Each controller and runner will increment the port by 1" default:"http://localhost:8892"`
IngressBind *url.URL `help:"Starting endpoint to bind to for http ingress" default:"http://localhost:8891"`
DBPort int `help:"Port to use for the database." default:"54320"`
DBPort int `help:"Port to use for the database." default:"15432"`
Recreate bool `help:"Recreate the database even if it already exists." default:"false"`
Controllers int `short:"c" help:"Number of controllers to start." default:"1"`
Background bool `help:"Run in the background." default:"false"`
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
environment:
POSTGRES_PASSWORD: secret
ports:
- 54320:5432
- 15432:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 1s
Expand Down
4 changes: 2 additions & 2 deletions integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func Fail(next Action, msg string, args ...any) Action {
// fetched and returns a row's column values
func GetRow(t testing.TB, ic TestContext, database, query string, fieldCount int) []any {
Infof("Querying %s: %s", database, query)
db, err := sql.Open("pgx", fmt.Sprintf("postgres://postgres:secret@localhost:54320/%s?sslmode=disable", database))
db, err := sql.Open("pgx", fmt.Sprintf("postgres://postgres:secret@localhost:15432/%s?sslmode=disable", database))
assert.NoError(t, err)
defer db.Close()
actual := make([]any, fieldCount)
Expand Down Expand Up @@ -326,7 +326,7 @@ func CreateDB(t testing.TB, module, dbName string, isTestDb bool) {
dbName += "_test"
}
Infof("Creating database %s", dbName)
db, err := sql.Open("pgx", "postgres://postgres:secret@localhost:54320/ftl?sslmode=disable")
db, err := sql.Open("pgx", "postgres://postgres:secret@localhost:15432/ftl?sslmode=disable")
assert.NoError(t, err, "failed to open database connection")
t.Cleanup(func() {
err := db.Close()
Expand Down
2 changes: 1 addition & 1 deletion sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sql:
queries: "backend/controller/sql/queries.sql"
schema: "backend/controller/sql/schema"
database:
uri: postgres://localhost:54320/ftl?sslmode=disable&user=postgres&password=secret
uri: postgres://localhost:15432/ftl?sslmode=disable&user=postgres&password=secret
gen:
go:
package: "sql"
Expand Down

0 comments on commit b7f7554

Please sign in to comment.