# Stuck on #gt1 DNS for multiple questions

**URL:** <https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300>\
**Category:** Challenges\
**Tags:** challenge:dns-server\
**Created:** [December 5, 2024, 4:43am UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300 "2024-12-05T04:43:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpca01](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/hpca01/32/3237_2.png) [@hpca01](https://forum.codecrafters.io/u/hpca01)\
**Post date:** [December 5, 2024, 4:43am UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/1 "2024-12-05T04:43:37Z")

</div>

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:

```auto
[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:

```go
			// 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?

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 5, 2024, 4:51am UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/2 "2024-12-05T04:51:28Z")

</div>

I’ll take a look shortly.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 5, 2024, 5:35am UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/3 "2024-12-05T05:35:59Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/4/4b14052b7a79820f62f442b4f1c9c8c9c32c0c86.jpeg)

Suggestions:

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

---

<div class="post-metadata">

**Author:** ![hpca01](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/hpca01/32/3237_2.png) [@hpca01](https://forum.codecrafters.io/u/hpca01)\
**Post date:** [December 5, 2024, 3:07pm UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/4 "2024-12-05T15:07:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 15, 2024, 2:31pm UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/5 "2024-12-15T14:31:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [December 20, 2024, 2:31pm UTC](https://forum.codecrafters.io/t/stuck-on-gt1-dns-for-multiple-questions/3300/6 "2024-12-20T14:31:28Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
