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

Use dynamic service discovery for client dns routing #266

Conversation

jakubno
Copy link
Member

@jakubno jakubno commented Jan 29, 2025

Description

Use consul service discovery for sandbox DNS, this will allow us to swap API servers without problems with resolving DNS in client proxy

Copy link

linear bot commented Jan 29, 2025

@jakubno jakubno force-pushed the use-dynamic-service-discovery-for-client-dns-routing-e2b-1503 branch from bd4841c to ae81b8a Compare January 29, 2025 23:28
@jakubno jakubno added the improvement Improvement for current functionality label Jan 29, 2025
dnsServer := dns.New()
intPort, convErr := strconv.Atoi(port)
if convErr != nil {
log.Fatalf("Failed to convert DNS_PORT to int: %v\n", convErr)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to go through and change these log.Fatalf calls, but they call os.Exit which means defers don't run. (I'm generally of the opinion that log.Fatal should really only be used in the body of main() , and otherwise you should either panic or return an error). In any case, this function returns an error, so I think we should just do that here.

I'd also say it's probably fine to just default to 53, I'm not sure the case where this wouldn't be correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to string

dnsServer := dns.New()
intPort, convErr := strconv.Atoi(port)
Copy link
Contributor

Choose a reason for hiding this comment

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

in the start function (which takes an int) here we just convert it back to string (and if it's not a valid port number it'll error there.

Admittedly the Start method doesn't return in the foreground which means we either have to panic, or continue without a functioning DNS server (this has implications for #261).

While we're (I'm) being pedantic, a valid int isn't neccessarily a valid port number: port numbers have to be valid uint16 numbers and int is basically always an int64 (but sometimes an int32 though in practice we may be confident that we'll never need to run this software from a 32-bit build). So we could pass this and still have an invalid port number.

@@ -73,6 +73,9 @@ job "api" {
REDIS_URL = "${redis_url}"
# This is here just because it is required in some part of our code which is transitively imported
TEMPLATE_BUCKET_NAME = "skip"
ADMIN_TOKEN = var.admin_token
REDIS_URL = var.redis_url
Copy link
Contributor

Choose a reason for hiding this comment

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

this duplicates line 72-73, which is either unnecessary or confusing 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, some mistake in merge conflict

@@ -73,6 +73,9 @@ job "api" {
REDIS_URL = "${redis_url}"
# This is here just because it is required in some part of our code which is transitively imported
TEMPLATE_BUCKET_NAME = "skip"
ADMIN_TOKEN = var.admin_token
REDIS_URL = var.redis_url
DNS_PORT = 5353
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a particular reason to use a non-default DNS port?

Copy link
Member Author

@jakubno jakubno Jan 31, 2025

Choose a reason for hiding this comment

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

yes, there already running another DNS server on 53

Failed starting DNS server{error 26 0  failed to start DNS server: listen udp 0.0.0.0:53: bind: address already in use}

@jakubno jakubno force-pushed the use-dynamic-service-discovery-for-client-dns-routing-e2b-1503 branch from ae81b8a to 8cb2af0 Compare January 31, 2025 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants