hub: Commands randomly fail on Windows under WSL

When I run hub clone styled-components/vscode-styled-components, it simply does not do anything, doesn’t clone the repo, neither emits any message to the console. I don’t know why, because it doesn’t throw any errors, logs or anything, it just doesn’t do anything.

If I try to clone a repo using the syntax hub clone REPO, without the USER, it clones fine. Same if I use the whole URL hub clone https://github.com/styled-components/vscode-styled-components.git.

Weird thing, if I clone using the URL, and then clone using the USER/REPO syntax (hub clone styled-components/vscode-styled-components), it says fatal: destination path 'vscode-styled-components' already exists and is not an empty directory., so I imagine that when I reproduce the bug, hub is trying to do something, but failing silently

Any ideas why this is happening? Or where I can look for clues (logs or anything)?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@mislav - I modified cmd.go like the following

// under func (cmd *Cmd) Exec() error {
-        return syscall.Exec(binary, args, os.Environ())
+        execErr := syscall.Exec(binary, args, os.Environ())
+        if execErr != nil {
+               panic(execErr)
+        }
+        return execErr

and received

cannot allocate memory

goroutine 1 [running]:
panic(0x726f00, 0xc00035a2c8)
        /usr/lib/go/src/runtime/panic.go:513 +0x1b9
github.com/github/hub/cmd.(*Cmd).Exec(0xc000020240, 0x1, 0x9f2c00)
        /home/phil/go/src/github.com/github/hub/cmd/cmd.go:93 +0x33b
github.com/github/hub/cmd.(*Cmd).Run(0xc000020240, 0xc000020240, 0x7fffcd14be93)
        /home/phil/go/src/github.com/github/hub/cmd/cmd.go:60 +0x2b
github.com/github/hub/commands.executeCommands(0xc00000e070, 0x1, 0x1, 0x1, 0xc000094300, 0x2)
        /home/phil/go/src/github.com/github/hub/commands/runner.go:153 +0x8e
github.com/github/hub/commands.(*Runner).Call(0xc000058e10, 0x9f2c00, 0xc0000e24d0, 0x5, 0xc000094398, 0xc000000300, 0xc000116d20)
        /home/phil/go/src/github.com/github/hub/commands/runner.go:127 +0x214
github.com/github/hub/commands.(*Runner).Execute(0xc000058e10, 0x7960a0, 0xc0000adf88, 0x407230, 0xc000084058)
        /home/phil/go/src/github.com/github/hub/commands/runner.go:100 +0x3af
main.main()
        /home/phil/go/src/github.com/github/hub/main.go:16 +0x51

My info

❯ hub --version
git version 2.20.1
hub version 2.7.1

# I'm also using Windows 10: WSL
❯ lsb_release -a
LSB Version:    1.4
Distributor ID: Arch
Description:    Arch Linux
Release:        rolling
Codename:       n/a

❯ zsh --version
zsh 5.6.2 (x86_64-pc-linux-gnu)

I have the same “random” symptom as well. When it works, the memory allocation error doesn’t occur

It also seems memory allocation errors are common in WSL, though I can’t seem to find a workaround. I’ll keep searching.

Edit

I added some memory output code to prove plenty of free memory existed

func PrintMemUsage() {
        var m runtime.MemStats
        runtime.ReadMemStats(&m)
        // For info on each, see: https://golang.org/pkg/runtime/#MemStats
        fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
        fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
        fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
        fmt.Printf("\tNumGC = %v\n", m.NumGC)
}

func bToMb(b uint64) uint64 {
    return b / 1024 / 1024
}

then modified the exec call again to the following

// under func (cmd *Cmd) Exec() error {
        PrintMemUsage()
        execErr := syscall.Exec(binary, args, os.Environ())
        if execErr != nil {
                ui.Errorln(execErr)
                PrintMemUsage()
        }
        return execErr

which resulted in the output

Alloc = 2 MiB   TotalAlloc = 11 MiB     Sys = 68 MiB    NumGC = 4
cannot allocate memory
Alloc = 2 MiB   TotalAlloc = 11 MiB     Sys = 68 MiB    NumGC = 4

Edit 2

I found a workaround which is to always run the cmd.Spawn even when in linux. e.g.

-        if runtime.GOOS == "windows" {
                return cmd.Spawn()
-        } else {
-              return cmd.Exec()
-        }

I use hub for very minimal purposes so this is fine for me.

If you want me to further debug then please let me know.