Google App Engine / Golang development (GAE)

Hi folks

I'm trying to set up a Google App Engine dev environment on my FreeBSD 9 (amd64) machine. Just to make things more interesting I'd like to use the Go (golang) language. Whilst trying the "Hello, World" tutorial, I've hit a problem which I think I understand but which I don't know how to solve:

When I try to execute the Hello World app in the local dev app server (dev_appserver.py myapp) I get a stack trace on the console, at the heart of which is the message:

Code:
ELF Binary type "0" unknown

I'm using the Linux 386 Google App Engine SDK as offered by Google:

Code:
Linux 32-bit	1.7.2 - 2012-09-18	go_appengine_sdk_linux_386-1.7.2.zip

Now, I'm presuming my error is because the local (Linux-targetted) app server compiles the Go app and produces binaries targeting a Linux 386 environment, which my FreeBSD system doesn't recognise natively. Is that anywhere close to the truth? I'm a bit hazy on that stuff so if my diagnosis is wrong please correct me!

I'm running linux_base-f10-10_4.

Either way, can anyone suggest any possible workarounds I can try to get past this problem?

Thanks all,

sim
 
You probably want to run this with python that has been built for linux. I don't think there is a port for it, but it should install fine from a binary package(for the type of your linux_base, RPM if you used Fedora linux_base port) or build it from source. Python is probably trying to load binary modules that were compiled for linux.
 
That's an interesting suggestion, I hadn't considered it to be a possible python problem. Since I last wrote I tried brandelfing the go-app-builder binary (which appeared to be the source of the error) as a Linux binary - now instead of the Unknown binary type error I get:

Code:
sim@tma1> dev_appserver.py myapp
INFO     2012-10-17 12:20:57,031 appcfg.py:585] Checking for updates to the SDK.
INFO     2012-10-17 12:20:57,373 appcfg.py:603] The SDK is up to date.
WARNING  2012-10-17 12:20:57,373 datastore_file_stub.py:518] Could not read datastore data from /tmp/dev_appserver.datastore
INFO     2012-10-17 12:20:57,400 dev_appserver_multiprocess.py:655] Running application dev~helloworld on port 8080: http://localhost:8080
INFO     2012-10-17 12:20:57,401 dev_appserver_multiprocess.py:657] Admin console is available at: http://localhost:8080/_ah/admin
INFO     2012-10-17 12:20:59,078 __init__.py:453] building _go_app
ERROR    2012-10-17 12:20:59,103 dev_appserver.py:3003] Compile error:



INFO     2012-10-17 12:20:59,103 dev_appserver.py:3056] "GET / HTTP/1.1" 500 -
INFO     2012-10-17 12:20:59,252 __init__.py:453] building _go_app
ERROR    2012-10-17 12:20:59,275 dev_appserver.py:3003] Compile error:



INFO     2012-10-17 12:20:59,276 dev_appserver.py:3056] "GET /favicon.ico HTTP/1.1" 500 -

I also tried symlinking the go binary provided in the app engine suite with the native go binary already installed and working on my system (via Ports). That apparently made no difference.

I'll have a look at your python suggestion, thanks.

sim
 
Well that was my hunch about the problem. I can probably point to exact problem if I can see full traceback or core dump.
 
Here we go... I've reverted all my hacks and reinstalled the original i386 Linux GAE SDK for Go, just as I started with. Without any hacks or workarounds, I get the following console output when trying to browse the dev app server at 127.0.0.1:8080:

Code:
sim@tma1> dev_appserver.py myapp
INFO     2012-10-17 13:06:26,644 appcfg.py:585] Checking for updates to the SDK.
INFO     2012-10-17 13:06:27,072 appcfg.py:603] The SDK is up to date.
WARNING  2012-10-17 13:06:27,072 datastore_file_stub.py:518] Could not read datastore data from /tmp/dev_appserver.datastore
INFO     2012-10-17 13:06:27,105 dev_appserver_multiprocess.py:655] Running application dev~helloworld on port 8080: http://localhost:8080
INFO     2012-10-17 13:06:27,105 dev_appserver_multiprocess.py:657] Admin console is available at: http://localhost:8080/_ah/admin
INFO     2012-10-17 13:06:34,171 __init__.py:453] building _go_app
ELF binary type "0" not known.
ERROR    2012-10-17 13:06:34,186 dev_appserver.py:3018] Exception encountered handling request
Traceback (most recent call last):
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 2954, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 2824, in _Dispatch
    base_env_dict=env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 707, in Dispatch
    base_env_dict=base_env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 1772, in Dispatch
    self._module_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 1590, in ExecuteCGI
    env, infile, outfile)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 521, in execute_go_cgi
    GO_APP.make_and_run(env)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 424, in make_and_run
    self.build(go_files)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 470, in build
    raise Exception('cannot call go-app-builder', e)
Exception: ('cannot call go-app-builder', OSError(8, 'Exec format error'))
INFO     2012-10-17 13:06:34,188 dev_appserver.py:3056] "GET / HTTP/1.1" 500 -
INFO     2012-10-17 13:06:34,424 __init__.py:453] building _go_app
ELF binary type "0" not known.
ERROR    2012-10-17 13:06:34,441 dev_appserver.py:3018] Exception encountered handling request
Traceback (most recent call last):
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 2954, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 2824, in _Dispatch
    base_env_dict=env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 707, in Dispatch
    base_env_dict=base_env_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 1772, in Dispatch
    self._module_dict)
  File "/usr/local/share/google-appengine/google/appengine/tools/dev_appserver.py", line 1590, in ExecuteCGI
    env, infile, outfile)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 521, in execute_go_cgi
    GO_APP.make_and_run(env)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 424, in make_and_run
    self.build(go_files)
  File "/usr/local/share/google-appengine/google/appengine/ext/go/__init__.py", line 470, in build
    raise Exception('cannot call go-app-builder', e)
Exception: ('cannot call go-app-builder', OSError(8, 'Exec format error'))
INFO     2012-10-17 13:06:34,441 dev_appserver.py:3056] "GET /favicon.ico HTTP/1.1" 500 -

And here's a copy of the browser output

Unfortunately my Python skills tend to zero... :r

Thanks

sim
 
ok, try # brandelf -t Linux /path/to/go-app-builder should at least fix the "ELF binary type "0" not known." error.
 
Agreed. I've just reapplied brandelf thus:

Code:
root@tma1> brandelf -t Linux /usr/local/share/google-appengine/goroot/bin/go-app-builder

and that gets us to the console output shown in post #3. The browser output shows only the words 'Compile Error: ' with nothing more.

The google-appengine dir contains two dev_appserver.py files - one at the base which appears to be a small (<200 line) launcher, and what is presumably the real script at
google-appengine/google/appengine/tools/dev_appserver. Looking at line 3003 of this script (indicated in the error above) shows this code block:

Code:
        response.body = cStringIO.StringIO(new_response)
        multiprocess.GlobalProcess().RequestComplete(self, response)
...
...
...
#LINE 3003:
except CompileError, e:
        msg = 'Compile error:\n' + e.text + '\n'
        logging.error(msg)
        self.send_response(httplib.INTERNAL_SERVER_ERROR, 'Compile error')
        self.wfile.write('Content-Type: text/plain; charset=utf-8\r\n\r\n')
        self.wfile.write(msg)

That at least tallies with the symptoms shown, although I haven't yet looked any deeper.

sim
 
Well what you want is a full traceback, to get one you can just comment out whole "except" block with #. This will cause default behavior of exception and python will spit out a traceback.
 
Actually disregard my last post, in that case you also need to remove the 'try:' bit as well or it will cause syntax error. just replace the previous except block with:

Code:
except:
    import sys
    import traceback
    traceback.print_tb(sys.exc_info()[2])

It should give you a traceback for the exception.
 
wait, didn't the OP mention he was using the 64 bit FreeBSD, and i386 GAE SDK? perhaps that's the issue? try using the x86_64 GAE SDK instead?
 
expl said:
Actually disregard my last post, in that case you also need to remove the 'try:' bit as well or it will cause syntax error. just replace the previous except block with:

Code:
except:
    import sys
    import traceback
    traceback.print_tb(sys.exc_info()[2])

It should give you a traceback for the exception.

I just generated this error output before I saw your message, not sure if it's relevant. I'll look into your revised suggestion now... :)

sim
 
jnbek said:
wait, didn't the OP mention he was using the 64 bit FreeBSD, and i386 GAE SDK? perhaps that's the issue? try using the x86_64 GAE SDK instead?

Hi, I chose the i386 Linux package on the recollection that FreeBSD's Linux compatibility mode is 386. Have I misunderstood that?

sim
 
sim said:
I just generated this error output before I saw your message, not sure if it's relevant. I'll look into your revised suggestion now... :)

sim

Code:
    471     if gab_retcode != 0:
=>  472       raise dev_appserver.CompileError(p.stdout.read() + '\n' + p.stderr.read())

Seems like it calls 'go-app-builder' executable and then checks for return value and raises this exception if its not 0. You probably want to execute it directly for your hello world app and see what is up.
 
Back again...!

I confirmed that the problem is within the go-app-builder executable and as suggested have tried executing it directly at the command line.

before branding:
Code:
sim@nostromo> go-app-builder
ELF binary type "0" not known.
bash: /usr/local/go/bin/go-app-builder: cannot execute binary file

after brandelf -t Linux
Code:
sim@nostromo> go-app-builder 
Trace/BPT trap: 5 (core dumped)

From a very crude debug of the Python script that calls go-app-builder, I was able to deduce that go-app-builder is apparently called with the following parameters:

Code:
go-app-builder -app_base .../path-to-myapp -arch 6 -binary_name _go_app -dynamic \
-goroot /usr/local/share/google_appengine/goroot -unsafe -work_dir \
/home/sim/.cache/dev_appserver_dev~test1-sim_sim_8080_go_app_work_dir hello/hello.go

Calling the go-app-builder with these params directly results in the same Trace/BPT error as above.

I've compared the (Linux) goroot directory supplied with the appengine SDK with the one installed by the lang/go port and there are some differences, the most significant of which appears to be the GOROOT pkg directory - the FreeBSD one has a subdir 'freebsd_amd64' whereas the appengine installation has one called 'linux_386'. I wonder if this could be a part of the problem, noting that the ports version sets environment variables GO_OS (freebsd) and GO_ARCH (amd64).

I might try mixing and mashing the two go roots, but it seems rather hit and miss (for me at least!).

sim
 
Back
Top