markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.19k stars 60 forks source link

pkger hangs #19

Closed henderjon closed 5 years ago

henderjon commented 5 years ago

After go install github.com/markbates/pkger/cmd/pkger on my MBP/Mojave (10.14.6) using go version go1.13 darwin/amd64 pkger hangs when invoked. I've let it run for 10 min before CRL+Cing it.

Code includes this usage:

import (
    "net/http"
    "strconv"

    "github.com/markbates/pkger"
)

func HandleIndexHTML(w http.ResponseWriter, r *http.Request) {
    asset, err := pkger.Open("/ui/index.html")
    if err != nil {
        http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
    }

    w.Header().Add("Content-Type", "text/html")
    w.Header().Add("Content-Length", strconv.Itoa(len(asset)))
    w.Write(asset)
}

Am I misunderstanding the usage?

markbates commented 5 years ago

Can you provide a full reproducible example? This code snippet doesn’t show how the app is being used. When you say “it” hangs you don’t say what hangs. The app? The command? What do you mean by it hangs? I develop on a Mac, and haven’t seen hanging issues, but again you didn’t provide reproduction steps so it’s hard to help. Sorry.

markbates commented 5 years ago

Also, I’m not sure how you’re code example compiles either. Write takes a slice of bytes and you’re giving it a File struct.

henderjon commented 5 years ago

I should have given you more detail. I put this together as an example to isolate my issue. Given two files main.go and index.txt in the root of a module.

package main

import (
    "io"
    "log"
    "os"

    "github.com/markbates/pkger"
)

func main() {
    asset, err := pkger.Open("/index.txt")
    if err != nil {
        log.Fatalln("shouldn't get here")
    }

    io.Copy(os.Stdout, asset)
}

When I run pkger (as in the example) it hangs.

markbates commented 5 years ago

Given that code I can’t reproduce. The command an app work as expected.

henderjon commented 5 years ago

I upgraded to go version go1.13.4 darwin/amd64 and ran both the example I posted and your example from the README. Your example has been running for 11 min and the CPU% for the pkger process on my MBP has slowly risen from 5.5 to 28.4 and it's still running.

I'll poke around more to see if I can generate more detail.

markbates commented 5 years ago

Please. Like I said I can’t repro but I’m not sure Mojave yet.

-- Mark Bates

On Nov 8, 2019, at 9:09 AM, Jon Henderson notifications@github.com wrote:

 I upgraded to go version go1.13.4 darwin/amd64 and ran both the example I posted and your example from the README. Your example has been running for 11 min and the CPU% for the pkger process on my MBP has slowly risen from 5.5 to 28.4 and it's still running.

I'll poke around more to see if I can generate more detail.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

donatj commented 5 years ago

Coworker of @henderjon here. I'm getting a different problem with his program above.

I've made a test repo here you can see with his code here: https://github.com/donatj/pkgertest

I'm running the following from $GOPATH/src/github.com/donatj/pkgertest

$ pkger
2019/11/08 12:36:44 exit status 1: can't load package: package .: C source files not allowed when not using cgo or SWIG: isomacprog.c
: /Users/jdonat/gocode/src/github.com/donatj/pkgertest

I have a file isomacprog.c in my $HOME which I'm both confused and concerned why it's trying to scan/read. I suspect @henderjon 's problem with it hanging is it's trying to scan his entire home directory or filesystem at large.

markbates commented 5 years ago

The C error would be coming from the Go tool chain, but we should be able to prevent the error. It shouldn’t be scanning the HOME directory, obviously. Can you run pkger parse and pkger info and paste?

This could be a Mojave bug. But I can’t be sure.

donatj commented 5 years ago
$ pkger parse                                                                                                                                                                                                                      12:47:22
2019/11/08 12:49:26 exit status 1: can't load package: package .: C source files not allowed when not using cgo or SWIG: isomacprog.c
: /Users/jdonat/gocode/src/github.com/donatj/pkgertest

$ pkger info                                                                                                                                                                                                                    1↵ 12:49:26
{
 "Dir": "/Users/jdonat/gocode/src/github.com/donatj/pkgertest",
 "ImportPath": "github.com/donatj/pkgertest",
 "Module": {
  "path": "github.com/donatj/pkgertest",
  "main": true,
  "dir": "/Users/jdonat/gocode/src/github.com/donatj/pkgertest",
  "go_mod": "",
  "go_version": ""
 },
 "Name": "main"
}
henderjon commented 5 years ago

$pkger parse hangs for me

$ pkger info                                                                                                                                                                                                                                                                               127[2019-11-08 12:49:11]
{
 "Dir": "/Users/jehender/code/go/src/github.com/henderjon/test",
 "ImportPath": "github.com/henderjon/test",
 "Module": {
  "path": "github.com/henderjon/test",
  "main": true,
  "dir": "/Users/jehender/code/go/src/github.com/henderjon/test",
  "go_mod": "",
  "go_version": ""
 },
 "Name": "main"
}
markbates commented 5 years ago

I think I found the issue. Can you try this PR https://github.com/markbates/pkger/pull/20

donatj commented 5 years ago

It does appear to have fixed the issue for me.

henderjon commented 5 years ago

👍 That did it, working as expected.

Thank you!

markbates commented 5 years ago

Thanks for the bug! The repo helped me find the issue.

markbates commented 5 years ago

v0.10.1 has this fix