Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit fc76a9c

Browse files
author
Stephen Gutekanst
authored
app: resolve port :9000 conflicts (change to :49000) (#54466)
Apparently VS Code's Python support uses port 9000, so as long as we use it most VS Code Python devs can't run the app due to the port conflict with our services. This PR switches the app's blobstore to listen on `:49000` instead of `:9000`. My thinking for now is that we can centralize all "default endpoint" and "what host/port should I listen on?" into the `deploy` package, and for now just change ports to have a `4` in front of them to reduce the change of conflicts. Later, once we have them centralized in the `deploy` package we can easily modify that code to pick an unavailable port. This also binds blobstore to `127.0.0.1` (more secure), previously it was bound to `localhost`. ## Test plan To test this I did the following: 1. [x] Methodically searched our codebase for `9000` and vetted each instance, to ensure I didn't miss anything. 2. [x] Tested with `sg start app` and confirmed `sudo lsof -i -P | grep LISTEN | grep :9000` reported nothing while `sudo lsof -i -P | grep LISTEN | grep :49000` did. 3. [x] Created an app build with `./enterprise/dev/app/build.sh` and tested it: * [x] Confirmed embeddings generation (which get stored in blobstore) still works through the setup wizard 4. [x] Confirmed `sg start enterprise-codeintel` starts and runs Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent 77c70ed commit fc76a9c

File tree

11 files changed

+49
-14
lines changed

11 files changed

+49
-14
lines changed

cmd/blobstore/shared/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/blobstore/shared/shared.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ import (
1818
"github.com/sourcegraph/sourcegraph/cmd/blobstore/internal/blobstore"
1919
"github.com/sourcegraph/sourcegraph/internal/actor"
2020
"github.com/sourcegraph/sourcegraph/internal/conf"
21-
"github.com/sourcegraph/sourcegraph/internal/env"
21+
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
2222
"github.com/sourcegraph/sourcegraph/internal/goroutine"
2323
"github.com/sourcegraph/sourcegraph/internal/instrumentation"
2424
"github.com/sourcegraph/sourcegraph/internal/observation"
2525
"github.com/sourcegraph/sourcegraph/internal/service"
2626
"github.com/sourcegraph/sourcegraph/internal/trace"
2727
)
2828

29-
const port = "9000"
30-
3129
func shutdownOnSignal(ctx context.Context, server *http.Server) error {
3230
// Listen for shutdown signals. When we receive one attempt to clean up,
3331
// but do an insta-shutdown if we receive more than one signal.
@@ -75,10 +73,7 @@ func Start(ctx context.Context, observationCtx *observation.Context, config *Con
7573
defer cancel()
7674
g, ctx := errgroup.WithContext(ctx)
7775

78-
host := ""
79-
if env.InsecureDev {
80-
host = "127.0.0.1"
81-
}
76+
host, port := deploy.BlobstoreHostPort()
8277
addr := net.JoinHostPort(host, port)
8378
server := &http.Server{
8479
ReadTimeout: 75 * time.Second,

cmd/server/shared/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/server/shared/blobstore.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"path/filepath"
66

77
sglog "github.com/sourcegraph/log"
8+
9+
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
810
)
911

1012
func maybeBlobstore(logger sglog.Logger) []string {
@@ -14,7 +16,7 @@ func maybeBlobstore(logger sglog.Logger) []string {
1416
}
1517

1618
// Point at local blobstore endpoint.
17-
SetDefaultEnv("PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT", "http://127.0.0.1:9000")
19+
SetDefaultEnv("PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT", deploy.BlobstoreDefaultEndpoint())
1820
SetDefaultEnv("PRECISE_CODE_INTEL_UPLOAD_BACKEND", "blobstore")
1921

2022
// cmd/server-specific blobstore env vars

enterprise/internal/codeintel/shared/lsifuploadstore/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/internal/codeintel/shared/lsifuploadstore/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"strings"
55
"time"
66

7+
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
78
"github.com/sourcegraph/sourcegraph/internal/env"
89
"github.com/sourcegraph/sourcegraph/lib/errors"
910
)
@@ -40,7 +41,7 @@ func (c *Config) Load() {
4041

4142
if c.Backend == "blobstore" || c.Backend == "s3" {
4243
c.S3Region = c.Get("PRECISE_CODE_INTEL_UPLOAD_AWS_REGION", "us-east-1", "The target AWS region.")
43-
c.S3Endpoint = c.Get("PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT", "http://blobstore:9000", "The target AWS endpoint.")
44+
c.S3Endpoint = c.Get("PRECISE_CODE_INTEL_UPLOAD_AWS_ENDPOINT", deploy.BlobstoreDefaultEndpoint(), "The target AWS endpoint.")
4445
c.S3UsePathStyle = c.GetBool("PRECISE_CODE_INTEL_UPLOAD_AWS_USE_PATH_STYLE", "false", "Whether to use path calling (vs subdomain calling).")
4546
ec2RoleCredentials := c.GetBool("PRECISE_CODE_INTEL_UPLOAD_AWS_USE_EC2_ROLE_CREDENTIALS", "false", "Whether to use the EC2 metadata API, or use the provided static credentials.")
4647

enterprise/internal/embeddings/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/internal/embeddings/uploadstore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/sourcegraph/sourcegraph/lib/errors"
88

9+
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
910
"github.com/sourcegraph/sourcegraph/internal/env"
1011
"github.com/sourcegraph/sourcegraph/internal/observation"
1112
"github.com/sourcegraph/sourcegraph/internal/uploadstore"
@@ -41,7 +42,7 @@ func (c *EmbeddingsUploadStoreConfig) Load() {
4142

4243
if c.Backend == "blobstore" || c.Backend == "s3" {
4344
c.S3Region = c.Get("EMBEDDINGS_UPLOAD_AWS_REGION", "us-east-1", "The target AWS region.")
44-
c.S3Endpoint = c.Get("EMBEDDINGS_UPLOAD_AWS_ENDPOINT", "http://blobstore:9000", "The target AWS endpoint.")
45+
c.S3Endpoint = c.Get("EMBEDDINGS_UPLOAD_AWS_ENDPOINT", deploy.BlobstoreDefaultEndpoint(), "The target AWS endpoint.")
4546
c.S3UsePathStyle = c.GetBool("EMBEDDINGS_UPLOAD_AWS_USE_PATH_STYLE", "false", "Whether to use path calling (vs subdomain calling).")
4647
ec2RoleCredentials := c.GetBool("EMBEDDINGS_UPLOAD_AWS_USE_EC2_ROLE_CREDENTIALS", "false", "Whether to use the EC2 metadata API, or use the provided static credentials.")
4748

internal/conf/deploy/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/conf/deploy/endpoints.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package deploy
2+
3+
import (
4+
"github.com/sourcegraph/sourcegraph/internal/env"
5+
)
6+
7+
// BlobstoreEndpoint returns the default blobstore endpoint that should be used for this deployment
8+
// type.
9+
func BlobstoreDefaultEndpoint() string {
10+
if IsApp() {
11+
return "http://127.0.0.1:49000"
12+
}
13+
if IsSingleBinary() {
14+
return "http://127.0.0.1:9000"
15+
}
16+
return "http://blobstore:9000"
17+
}
18+
19+
// BlobstoreHostPort returns the host/port that should be listened on for this deployment type.
20+
func BlobstoreHostPort() (string, string) {
21+
if IsApp() {
22+
return "127.0.0.1", "49000"
23+
}
24+
if env.InsecureDev || IsSingleBinary() {
25+
return "127.0.0.1", "9000"
26+
}
27+
return "", "9000"
28+
}

0 commit comments

Comments
 (0)