Skip to content

[Go SDK] Let JobOptions provide the gRPC dialer - #41744

Open
igor-dv wants to merge 2 commits into
apache:masterfrom
igor-dv:go-runnerlib-dial
Open

igor-dv wants to merge 2 commits into
apache:masterfrom
igor-dv:go-runnerlib-dial

Conversation

@igor-dv

@igor-dv igor-dv commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

fixes #41745

Execute always dials a gRPC connection for the job service and another for artifact staging, then closes both when the job ends. A process that submits many jobs in a row can leave a lot of sockets in TIME_WAIT.

JobOptions.Dial lets the caller provide those connections. Execute does not close what Dial returns. Dial is called once per endpoint (job and artifact may differ). If Dial is nil, Execute still dials with grpcx.Dial and closes as before.

The exported Stage is unchanged: it still dials and closes.

No breaking change: Dial is a new field on JobOptions, zero value is nil.

Example

type connCache struct {
	mu sync.Mutex
	m  map[string]*grpc.ClientConn
}

var conns = &connCache{m: map[string]*grpc.ClientConn{}}

func (c *connCache) dial(ctx context.Context, endpoint string, timeout time.Duration) (*grpc.ClientConn, error) {
	c.mu.Lock()
	defer c.mu.Unlock()
	if cc, ok := c.m[endpoint]; ok {
		return cc, nil
	}
	cc, err := grpcx.Dial(ctx, endpoint, timeout)
	if err != nil {
		return nil, err
	}
	c.m[endpoint] = cc
	return cc, nil
}

res, err := runnerlib.Execute(ctx, pipeline, endpoint, &runnerlib.JobOptions{
	Name:     name,
	Worker:   *jobopts.WorkerBinary,
	Loopback: jobopts.IsLoopback(),
	Dial:     conns.dial,
}, *jobopts.Async)

@github-actions github-actions Bot added go runners size/m M: 50-249 lines changed labels Nov 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR introduces JobOptions.Dial (DialFunc) to allow callers of runnerlib.Execute to supply and reuse gRPC connections for the job service and artifact staging endpoints without Execute closing them. The implementation is clean, backwards-compatible, and properly preserves the default grpcx.Dial and connection teardown behavior when Dial is nil.

🔍 General Feedback

  • The dialEndpoint helper and stage refactoring cleanly separate connection ownership between caller-provided and default-dialed connections.
  • In execute_test.go, TestExecute_customDialNotClosed can be improved to exercise the artifact staging dial path (stage) and avoid leaving temporary files in os.TempDir().

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @lostluck for label go.
Backup reviewer: jrmccluskey (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go SDK] runnerlib.Execute always dials a new job service connection

1 participant