Stuck on #gt1 DNS for multiple questions

I’m stuck on Stage #(change to your stage, ex. #GT1).

The 1:1 questions and answers work just fine, but for sending a query for 2 questions separately is causing an io timeout

Here are my logs:

[your_program] There are more than 1 questions!
[your_program] [{QName:abc.longassdomainname.com QType:1 QClass:1} {QName:def.longassdomainname.com QType:1 QClass:1}]
[your_program] Iterating over [{QName:abc.longassdomainname.com QType:1 QClass:1}] of [{QName:abc.longassdomainname.com QType:1 QClass:1} {QName:def.longassdomainname.com QType:1 QClass:1}]
[your_program] [{QName:abc.longassdomainname.com QType:1 QClass:1}]
[your_program] Question: {QName:abc.longassdomainname.com QType:1 QClass:1}
[your_program] Output bytes: [220 101 129 0 0 1 0 1 0 0 0 0 3 97 98 99 17 108 111 110 103 97 115 115 100 111 109 97 105 110 110 97 109 101 3 99 111 109 0 0 1 0 1]
[your_program] Transmitted Query of N bytes  43
[tester::#YC9] DNS query failed: read udp 127.0.0.1:34588->127.0.0.1:2053: i/o timeout.
[tester::#YC9] If you are seeing this after a while then it is likely that your server is not responding with appropriate id
[tester::#YC9] Test failed

And here’s a snippet of my code:

			// If resolver, we need to forward
			remoteUdpConn, _ := net.Dial("udp", ip)
			if len(resp.Questions) > 1 {
				// if more than 1 question, we need to split up
				fmt.Println("There are more than 1 questions!")
				fmt.Printf("%+v\n", resp.Questions)
				for _, ques := range resp.Questions {
					//iterate over questions
					//turn question into its own separate DNS query
					query := resp.AnswerFrom()
					query.Questions = []Question{ques}
					fmt.Printf("Iterating over %+v of %+v\n", query.Questions, resp.Questions)

					//fire off query and get back response
					size, err := remoteUdpConn.Write(query.ToBytes())
					fmt.Println("Transmitted Query of N bytes ", size)
					if err != nil {
						fmt.Println("failed to write to DNS! ", err)
					}
					buf := make([]byte, 512)
					size, err = remoteUdpConn.Read(buf)
					if err != nil {
						fmt.Println("Error on receiving ", err)
					}
					fmt.Printf("Recieved %d bytes back from %+v\n", size, remoteUdpConn.RemoteAddr().String())
					//parse response with ANSWER
				}

As you can see the code splits up a multi-question message into a separate message and transmits it, but never gets a response, instead it gets timed out. Is there a timing component to this test? Should I be doing the queries on a separat e thread vs the main thread?

I’ll take a look shortly.

Hi @hpca01, I tried running your code against the previous stages, but it’s no longer passing Stage #XM2 (Write answer section).

Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.

Thanks for the quick response, will go back and validate the prior section is working

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!