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

Limiting hosts per line works for first line, but after that each item goes on its own line #51

Closed
rfay opened this issue Oct 28, 2023 · 10 comments · Fixed by #52 or #53
Closed

Comments

@rfay
Copy link

rfay commented Oct 28, 2023

This isn't a huge deal, but probably not what's intended.

Using the artifacts in ddev/ddev#4805 and running the manual test there,

for item in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do 
  sudo ddev hostname a$item.ddev.site 127.0.0.1
done

You'll see the results are that the first hosts line goes to 8, but after that they are all on separate lines.

127.0.0.1 localhost junk.ddev.site a1.ddev.site a2.ddev.site a3.ddev.site a4.ddev.site a5.ddev.site a6.ddev.site
127.0.0.1 a15.ddev.site
127.0.0.1 a14.ddev.site
127.0.0.1 a13.ddev.site
127.0.0.1 a12.ddev.site
127.0.0.1 a11.ddev.site
127.0.0.1 a10.ddev.site
127.0.0.1 a9.ddev.site
127.0.0.1 a8.ddev.site
127.0.0.1 a7.ddev.site

Code from https://github.com/rfay/ddev/blob/b71df9536b015854d9ee3cc7829861ef34e0e909/pkg/ddevapp/hostname_mgt.go#L135-L146 is

	hosts, err := goodhosts.NewCustomHosts(osHostsFilePath)

	if err != nil {
		return err
	}
	err = hosts.Add(ip, name)
	if err != nil {
		return err
	}
	hosts.HostsPerLine(8)
	err = hosts.Flush()
	return err
@luthermonson
Copy link
Contributor

I thought I had a test for that, I'll check this out today

@luthermonson
Copy link
Contributor

the good thing is i can recreate the problem and it's being caused by hosts per line being called after every add. this is definitely a bug and ill investigate further but here is how to recreate the problem with just the hostsfile package

// this works
func Test_rfay(t *testing.T) {
	hosts := newHosts()
	for i := 1; i <= 50; i++ {
		hosts.Add("127.0.0.1", fmt.Sprintf("a%d.ddev.site", i))
		
	}
	hosts.HostsPerLine(8) // 8
	fmt.Println(hosts.String())
}
// this does similar to what you showed me
func Test_rfay(t *testing.T) {
	hosts := newHosts()
	for i := 1; i <= 50; i++ {
		hosts.Add("127.0.0.1", fmt.Sprintf("a%d.ddev.site", i))
		hosts.HostsPerLine(8) // 8
	}
	fmt.Println(hosts.String())
}

@luthermonson
Copy link
Contributor

luthermonson commented Oct 29, 2023

based on testing you should be fine with the changes in the PR i just posted. i can leave this up as a branch for a bit if you want to test and confirm before we make the merge and release.

thanks again for your help tracking this down

@rfay
Copy link
Author

rfay commented Oct 29, 2023

I think the current structure was a workaround for

I'll change it to the structure you suggest. Thanks so much!

@rfay
Copy link
Author

rfay commented Oct 29, 2023

Oh, I guess I can't. Normally only one host is added at a time, per ddev hostname call.

Here's the code, https://github.com/ddev/ddev/blob/b71df9536b015854d9ee3cc7829861ef34e0e909/pkg/ddevapp/hostname_mgt.go#L127-L147

Can you see a workaround?

But I see

is on the way, thanks!

@luthermonson
Copy link
Contributor

https://github.com/goodhosts/hostsfile/releases/tag/v0.1.5 try this and see if youre good

@rfay
Copy link
Author

rfay commented Oct 29, 2023

Sadly, it has a panic now,

panic: runtime error: index out of range [18] with length 1

goroutine 1 [running]:
github.com/goodhosts/hostsfile.(*Hosts).Add(0x140000ea000, {0x16f82faf4, 0x9}, {0x140000c0130?, 0x1, 0x1})
	/Users/rfay/workspace/ddev/vendor/github.com/goodhosts/hostsfile/hosts.go:179 +0x538
github.com/ddev/ddev/pkg/ddevapp.AddHostEntry({0x16f82fae6, 0xd}, {0x16f82faf4, 0x9})

I didn't change the calling code just updated the go.mod etc.

@luthermonson
Copy link
Contributor

luthermonson commented Oct 29, 2023

any chance you can ping me on gophers slack?

@luthermonson luthermonson reopened this Oct 29, 2023
@luthermonson
Copy link
Contributor

i believe me writng all tests to blank Hosts structs covered up a bug, can you vendor from this branch? i don't want to release again if this isn't the fix
#53

@luthermonson
Copy link
Contributor

confirmed fixed worked via chat outside of git, this is good and being released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants