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

Fixed wait for TUN to come up #1157

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

Revertron
Copy link
Contributor

So, the function waiting for TUN to come up never succeeds:

func waitForTUNUp(ch <-chan wgtun.Event) bool {
	t := time.After(time.Second * 5)
	for {
		select {
		case ev := <-ch:
			if ev == wgtun.EventUp {
				return true
			}
		case <-t:
			return false
		}
	}
}

I've tried the sleep for one second, and it works flawlessly on several PCs.

Another point - sometimes, if the service stop abruptly (in case of some errors) there is an old hidden device in the system, that we need to uninstall, and then create new.

@Revertron
Copy link
Contributor Author

BTW, in RiV-mesh they've ditched the waiting for event too. And added a crutch:

		for i := 1; i < 10; i++ {
			if err = tun.setupAddress(addr); err != nil {
				tun.log.Errorln("Failed to set up TUN address:", err)
				log.Printf("waiting...")
				if i > 8 {
					return err
				} else {
					time.Sleep(time.Duration(2*i) * time.Second)
				}
			} else {
				break
			}
		}

@Revertron
Copy link
Contributor Author

Maybe I'm blind, but I don't even see any events like TunUp in the sources:
https://github.com/WireGuard/wireguard-go/blob/master/tun/tun_windows.go
It's like they just notify on MTU change and that's all.

}
if !waitForTUNUp(iface.Events()) {
return fmt.Errorf("TUN did not come up in time")
tun.log.Printf("Creating TUN")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe don't need so many logging lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed this line, but I think it is better to leave the others.

src/tun/tun_windows.go Outdated Show resolved Hide resolved
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM!

@neilalexander neilalexander merged commit 5e5de3a into yggdrasil-network:develop Aug 6, 2024
15 checks passed
@Revertron Revertron deleted the fix_windows_tun branch August 6, 2024 09:31
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.

2 participants