Go 1.11: "Metadata fetch failed"

1,054 views
Skip to first unread message

Yohann Coppel

unread,
Oct 28, 2018, 8:23:43 PM10/28/18
to google-appengine-go
Hi,

I am trying to update/convert one of my relatively big apps to Go 1.11.

I would like to continue using the google.golang.org/appengine package for now, and then slowly transition to the cloud apis once everything is working. The doc says this is still supported [2].

But I'm a bit confused by how I am supposed to do the development now. The short documentation just says "use go run" [1]. But I feel like a lot is missing.
I still need a dev server? Probably yes, at least I would love to still have one available (for the datastore and other apis). How do I run the binary exactly, do I need env variables set ?

If I just run the main, I get an error when trying to make a datastore query:

> env PORT=9090 go run main.go
2018/10/27 23:24:22 Listening on port 9090
2018/10/27 23:24:31 http: panic serving 127.0.0.1:53880: Metadata fetch failed for 'instance/attributes/gae_project': Get http://metadata/computeMetadata/v1/instance/attributes/gae_project: dial tcp: lookup metadata on 127.0.0.53:53: server misbehaving
goroutine 39 [running]:
net/http.(*conn).serve.func1(0xc00053c0a0)
        /usr/local/epath/go/src/net/http/server.go:1746 +0xd0
panic(0xa609c0, 0xc0003f20e0)
        /usr/local/epath/go/src/runtime/panic.go:513 +0x1b9
google.golang.org/appengine/datastore.NewKey(0xc81a20, 0xc000267180, 0xb7c22d, 0x2, 0xc0002e8420, 0xc, 0x0, 0x0, 0xb0)

It's trying to make a query to http://metadata/... ? On 127.0.0.53:53 !??! Systemd?


Out of desperation, I tried with dev_appserver.py, the above works, but I get another error during the datastore query: "not an App Engine context".

2018/10/28 06:49:09 panic occurred: not an App Engine context
goroutine 52 [running]:
panic(0xa93f40, 0xc0000b6ca0)
/usr/local/epath/go/src/runtime/panic.go:513 +0x1b9
google.golang.org/appengine/internal.Logf(0xc81cc0, 0xc0003c8e80, 0x1, 0xb941f8, 0x21, 0xc000291770, 0x3, 0x3)
google.golang.org/appengine/log.Infof(0xc81cc0, 0xc0003c8e80, 0xb941f8, 0x21, 0xc000291770, 0x3, 0x3)

This looks kind of expected to me, as it is indeed not an appengine context... Building without tags mean that appengine.NewContext is just an alias for context.Context. I also tried building with the appengine tag (using a bit of trickery...) but that doesn't work either since dev_appserver doesn't include the "appengine" package anymore [2], used by some of the files with the appengine build tag (e.g. [4])

So back to running main.go with go run. I just feel like I need to set some environment variables, other than just PORT. I couldn't find any documentation on that really. And also, once that is done, probably I should also run a dev server, so that my binary can use various services from it (users, datastore, task queues, etc -- again, I will migrate those later, as as I understand this is still supported)

FWIW, I'm using google.golang.org/appengine on the log-security-ticket-fix branch, see [3] which was supposed to be a fix for Go 1.11.

What am I doing wrong or missing? :)

Thanks,

Steven Buss

unread,
Oct 29, 2018, 12:08:02 PM10/29/18
to yoh...@gmail.com, google-appengine-go
> I would like to continue using the google.golang.org/appengine package for now
> I still need a dev server? Probably yes

Yes, to continue using google.golang.org/appengine you need to do two things:

1) call appengine.Main() in your func main()
2) Use dev_appserver.py to run your app

I think you aren't doing #1, which is why you're getting the "not an appengine context" error message. Can you confirm that?

> So back to running main.go with go run. I just feel like I need to set some environment variables, other than just PORT. I couldn't find any documentation on that really. And also, once that is done, probably I should also run a dev server, so that my binary can use various services from it (users, datastore, task queues, etc -- again, I will migrate those later, as as I understand this is still supported)

We set several environment variables in production, which you may want to duplicate locally: https://cloud.google.com/appengine/docs/standard/go111/runtime

And yes, you'll need to use dev_appserver.py until you no longer depend on google.golang.org/appengine

--
You received this message because you are subscribed to the Google Groups "google-appengine-go" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine-go/65c12eeb-d672-434e-90ed-588ceeec1723%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yohann Coppel

unread,
Oct 29, 2018, 11:35:30 PM10/29/18
to google-appengine-go


On Monday, October 29, 2018 at 9:08:02 AM UTC-7, Steven Buss wrote:
> I would like to continue using the google.golang.org/appengine package for now
> I still need a dev server? Probably yes

Yes, to continue using google.golang.org/appengine you need to do two things:

1) call appengine.Main() in your func main()
2) Use dev_appserver.py to run your app

I think you aren't doing #1, which is why you're getting the "not an appengine context" error message. Can you confirm that?

Ha, that was it. appengine.Main(). I didn't realize the two were linked, and since I'm converting from the old-old format (no main package/function at all), I went straight to the fully "manual" main.

 

> So back to running main.go with go run. I just feel like I need to set some environment variables, other than just PORT. I couldn't find any documentation on that really. And also, once that is done, probably I should also run a dev server, so that my binary can use various services from it (users, datastore, task queues, etc -- again, I will migrate those later, as as I understand this is still supported)

We set several environment variables in production, which you may want to duplicate locally: https://cloud.google.com/appengine/docs/standard/go111/runtime

I didn't actually need them, I was just trying to make my binary work standalone. but that's not needed in dev_appserver. All good now.
 

And yes, you'll need to use dev_appserver.py until you no longer depend on google.golang.org/appengine

Thanks for the clarifications,

Best,
 

To unsubscribe from this group and stop receiving emails from it, send an email to google-appengine-go+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages