Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get-free-port: prevent duplicate ports on Linux #1478

Merged
merged 5 commits into from
May 17, 2024
Merged

Conversation

mjameswh
Copy link
Contributor

What changed

  • When assigning ephemeral ports for use by the Temporal Server, on all platforms except MacOS and Windows, immediately open a connection to that port, and force the connection into TIME_WAIT state. This avoids various race conditions that could happen due to the port being reallocated between the moment the port is obtained and the moment the server actually binds to that port. See get-free-port: prevent duplicate ports on Linux cli#564 for details.

@mjameswh mjameswh requested a review from a team as a code owner May 17, 2024 17:41
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM but let @Quinn-With-Two-Ns confirm

// Modified from Temporalite which itself modified from
// https://github.com/phayes/freeport/blob/95f893ade6f232a5f1511d61735d89b1ae2df543/freeport.go
// Copied and adapted from
// https://github.com/mjameswh/temporalio-cli/blob/6b5a708e51da89dbdfd4fda7b7219ae12bcd8ffb/temporalcli/devserver/freeport.go
Copy link
Member

Choose a reason for hiding this comment

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

Can point to PR instead of personal repo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Fixed.

if err != nil {
return "", 0, err
return "", 0, fmt.Errorf("failed to assign a free port: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "", 0, fmt.Errorf("failed to assign a free port: %v", err)
return "", 0, fmt.Errorf("failed to assign a free port: %w", err)

nit

@mjameswh mjameswh merged commit aa17647 into master May 17, 2024
14 checks passed
@mjameswh mjameswh deleted the get-free-port branch May 17, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants