Skip to content

Commit f9bf9fe

Browse files
authored
fix: pass LISTEN_ADDRESS to runner (knative#2901)
Signed-off-by: Matej Vašek <[email protected]>
1 parent 65de4ac commit f9bf9fe

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

pkg/functions/runner.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,12 @@ func runGo(ctx context.Context, job *Job) (err error) {
171171
cmd.Stderr = os.Stderr
172172

173173
// cmd.Cancel = stop // TODO: use when we upgrade to go 1.20
174-
// TODO: Update the functions go runtime to accept LISTEN_ADDRESS rather
175-
// than just port in able to allow listening on other interfaces
176-
// (keeping the default localhost only)
177-
if job.Host != "127.0.0.1" {
178-
fmt.Fprintf(os.Stderr, "Warning: the Go functions runtime currently only supports localhost '127.0.0.1'. Requested listen interface '%v' will be ignored.", job.Host)
179-
}
174+
180175
// See the 1.19 [release notes](https://tip.golang.org/doc/go1.19) which state:
181176
// A Cmd with a non-empty Dir field and nil Env now implicitly sets the PWD environment variable for the subprocess to match Dir.
182177
// The new method Cmd.Environ reports the environment that would be used to run the command, including the implicitly set PWD variable.
183178
// cmd.Env = append(cmd.Environ(), "PORT="+job.Port) // requires go 1.19
184-
cmd.Env = append(cmd.Env, "PORT="+job.Port, "PWD="+cmd.Dir)
179+
cmd.Env = append(cmd.Env, "LISTEN_ADDRESS="+net.JoinHostPort(job.Host, job.Port), "PWD="+cmd.Dir)
185180

186181
// Running asynchronously allows for the client Run method to return
187182
// metadata about the running function such as its chosen port.
@@ -274,7 +269,7 @@ func runPython(ctx context.Context, job *Job) (err error) {
274269

275270
func waitFor(ctx context.Context, job *Job, timeout time.Duration) error {
276271
var (
277-
uri = fmt.Sprintf("http://%s:%s%s", job.Host, job.Port, readinessEndpoint)
272+
uri = fmt.Sprintf("http://%s%s", net.JoinHostPort(job.Host, job.Port), readinessEndpoint)
278273
interval = 500 * time.Millisecond
279274
)
280275

0 commit comments

Comments
 (0)