go-wsl2-host icon indicating copy to clipboard operation
go-wsl2-host copied to clipboard

invalid memory address on start

Open goffinf opened this issue 5 years ago • 8 comments

Version: 0.3.4 Windows version: 2004 (OS Build 19041.264) - (Insiders: slow)

Hey Shayne,

Installation appeared to work correctly but shortly after the WSL2 Host service starts, its stops.

When I run debug I see the following:

C:\wsl2>.\wsl2host.exe debug
wsl2host.info(1): starting wsl2host service
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x50bd42]

goroutine 1 [running]:
github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service.Run(0x581560, 0xc00002c570, 0x2, 0x0)
        C:/Users/Shayne/Code/go-wsl2-host/cmd/wsl2host/pkg/service/service.go:87 +0x6b2
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.(*windowserver).Execute(0x688b80, 0xc00002c590, 0x1, 0x1, 0xc00003c180, 0xc00003c1e0, 0xc00000a540)
        C:/Users/Shayne/Code/go-wsl2-host/cmd/wsl2host/internal/service.go:33 +0x523
golang.org/x/sys/windows/svc/debug.Run(0x5545ff, 0x8, 0x57fea0, 0x688b80, 0x0, 0x0)
        C:/Users/Shayne/Code/go-wsl2-host/vendor/golang.org/x/sys/windows/svc/debug/service.go:40 +0x153
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.RunService(0x5545ff, 0x8, 0xc000010001)
        C:/Users/Shayne/Code/go-wsl2-host/cmd/wsl2host/internal/service.go:81 +0x1bf
main.main()
        C:/Users/Shayne/Code/go-wsl2-host/cmd/wsl2host/main.go:42 +0x384

I note the comment from this issue #21 and I do have Docker Desktop for Windows installed but not running ...

C:\wsl2>wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop-data    Stopped         2
  docker-desktop         Stopped         2
  Ubuntu-20.04           Running         2

Is that likely to be the problem ? ... ie do I need to uninstall DD4W (obviously I would prefer not to since I sometimes switch back and forth when I am testing about different run-time environments, but I will if wsl2host absolutely wont work if it is ?)

Great utility BTW :-)

Kind Regards

Fraser.

goffinf avatar Jun 07 '20 16:06 goffinf

In case its important ... I noted other issues that mentioned that the hosts file comments may be a problem or duplicate entries, etc ... so I stripped mine down so it just has this in it ..

172.26.215.139 sample.k3d.localhost

Thats what I am using at the moment to hit a K8s service hosted in WSL2, and obviously my interest here is to not have to continually update that IP address every time I restart WSL2

goffinf avatar Jun 07 '20 16:06 goffinf

Updated to version 0.3.5, but still see the same behaviour .. the service installs ok, but shortly after starting it stops. Running debug ..

.\wsl2host.exe debug
wsl2host.info(1): starting wsl2host service
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x50c352]

goroutine 1 [running]:
github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service.Run(0x5812a0, 0xc000088560, 0x2, 0x0)
        /workspaces/go-wsl2-host/cmd/wsl2host/pkg/service/service.go:92 +0x742
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.(*windowserver).Execute(0x687be0, 0xc000088580, 0x1, 0x1, 0xc000086120, 0xc000086180, 0xc00009e2c0)
        /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:33 +0x523
golang.org/x/sys/windows/svc/debug.Run(0x554639, 0x8, 0x57fc20, 0x687be0, 0x0, 0x0)
        /go/pkg/mod/golang.org/x/[email protected]/windows/svc/debug/service.go:40 +0x153
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.RunService(0x554639, 0x8, 0xc0000a0001)
        /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:81 +0x1bf
main.main()
        /workspaces/go-wsl2-host/cmd/wsl2host/main.go:42 +0x384

goffinf avatar Oct 14 '20 16:10 goffinf

Hey there, I've got the same problem.

PS C:\Users\username_admin\Documents> .\wsl2host.exe debug
wsl2host.info(1): starting wsl2host service
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x50c352]

goroutine 1 [running]:
github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service.Run(0x5812a0, 0xc00003c570, 0x2, 0x0)
        /workspaces/go-wsl2-host/cmd/wsl2host/pkg/service/service.go:92 +0x742
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.(*windowserver).Execute(0x687be0, 0xc00003c590, 0x1, 0x1, 0xc000016180, 0xc0000161e0, 0xc00000c4c0)
        /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:33 +0x523
golang.org/x/sys/windows/svc/debug.Run(0x554639, 0x8, 0x57fc20, 0x687be0, 0x0, 0x0)
        /go/pkg/mod/golang.org/x/[email protected]/windows/svc/debug/service.go:40 +0x153
github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.RunService(0x554639, 0x8, 0xc00002e001)
        /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:81 +0x1bf
main.main()
        /workspaces/go-wsl2-host/cmd/wsl2host/main.go:42 +0x384

Environment is a Windows 10 1909 (Build 18363.1082) machine inside a domain (domain.local) with two domain users (domain.local\username and domain.local\username_admin, the latter one should have local administrator permissions).

I do have a Docker Desktop for Windows instance running and a default hosts-file (comments and the 3 entries of docker).

I placed the wsl2host.exe inside of domain.local\username_admin's Documents folder, openend a Powershell prompt inside of that directory as administrator and ran .\wsl2host install, entered my admin credentials (Username: domain.local\username_admin) and it seemed like it worked. But debugging it always shows the runtime error from above.

RicoBrase avatar Oct 20 '20 08:10 RicoBrase

I also got the same error. Is there a fix?

vijaytilak avatar May 29 '21 10:05 vijaytilak

TBH I have given up on this and just use a couple of simple PowerShell scripts to update the hosts file to the current IP and to enable access to WSL on selected ports through the firewall so I can call into services hosted in k8s and docker running in WSL from my local network. The first does require a specific convention for naming host entries (they start with wsl.xxx) but it’s actually relatively sane and simple to maintain/expand if I need to. I keep a watch on this project in the hope that at some point this issue will be investigated and resolved, but in the mean time ... life goes on ;-)

goffinf avatar May 29 '21 10:05 goffinf

Well, at least you got something that works. Can you detail the steps to get to that point ?

I'm sure it would be useful to many of us struggling for a solution.

vijaytilak avatar May 29 '21 10:05 vijaytilak

It's giving me the same error.

vsg24 avatar Jul 02 '21 17:07 vsg24

@vijaytilak I have created a gist here: https://gist.github.com/goffinf/b545abdb865e90297a36b89ea1398681

It's a bit rough around the edges, but I have been using it for a year or so and on the whole it does what i need it to.

What it does:

  1. Gets the IP address of your chosen default WSL2 distro (you need to update the $distro param in the configure-wsl-ps1 script)
  2. Runs the script update-hosts.ps1 to update Windows hosts file entries where the hostname starts with wsl2 - all others are ignored (you can change that prefix if you prefer to use a different convention). It will also create a backup of the current hosts file before the update (be aware that the backup file is just called hosts.backup (no timestamp in the name) so it has the potential to overwrite with garbage if something goes wrong). On completion, the chosen default WSL distro will be terminated. A dialog will appear and you should choose to restart it (its just to ensure that the WSL /etc/hosts file is synced - unless you have that turned off !). Examples:

# wsl2 172.18.147.173 wsl2.ubuntu-20.04.local 172.18.147.173 wsl2.k3d.homelab 172.18.147.173 host.k3d.internal 172.18.147.173 wsl2.pi-hole ...

  1. The update-hosts.ps1 script also attempts to update the IP for the special hostname host.k3d.internal. This is specific to k3d which I run locally. If you don't it will just be ignored.
  2. Runs the script wsl2-enable-lan-access.ps1. This will create inbound firewall rules for ports exposed in WSL that you want to be able access from outside (for example, I run a CI agent, Vault service and K8s in WSL). If you don't need this, you can just comment the line in configure-wsl.ps1 that calls this script.

There are a couple of pauses and prompts which are included just to allow enough time for stuff to happen and reduce the risk of race conditions. They may/mat not be necessary but they work for me.

You may find on occasions that some other process is using the Windows hosts file and the script will fail. Its usually WSL itself. If that happens you can use something like Windows Process Explorer (sys-internals) to find and kill those process(es).

HTHs

Fraser

goffinf avatar Jul 08 '21 12:07 goffinf