Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tempest UI fails to load: Uncaught (in promise) TypeError: import object field 'env' is not an Object #15

Closed
troyjfarrell opened this issue May 22, 2023 · 11 comments

Comments

@troyjfarrell
Copy link
Contributor

I'm trying to get started with Tempest, but I know very little about web_asm.js and WebAssembly in general. I know that I have a non-standard setup, so I'm going to list versions of software. I would like you to tell me if any of these seem far from what you're using:

AlmaLinux 9 (like RHEL 9)
go 1.20.4 (binaries from golang.org)
binaryen version 113 (built from source)
capnproto-c++-0.10.4 (built from source)
bpf_asm from linux 6.3.3 (built from source)
tinygo 0.27.0 (built from source)
go-capnp v3.0.0-alpha.28
tempest 64eebec, except that I commented out line 290 of internal/server/main/external-api.go, so it would compile and I applied the change in #14.
config.json:

{
  "User": "tempest",
  "Group": "tempest",
  "Prefix": "/opt/tempest",
  "ExecPrefix": "/opt/tempest",
  "Bindir": "/opt/tempest/bin",
  "Libexecdir": "/opt/tempest/libexec",
  "Localstatedir": "/opt/tempest/var/lib",
  "WithGoCapnp": "../go-capnp",
  "WithWasmExecJs": "/usr/local/go/misc/wasm/wasm_exec.js",
  "TinyGo": true,
  "Args": [
    "--prefix=/opt/tempest",
    "--user",
    "tempest",
    "--group",
    "tempest",
    "--with-go-capnp=../go-capnp",
    "--with-wasm_exec.js=/usr/local/go/misc/wasm/wasm_exec.js"
  ]
}

Command line:

[root@tempest ~]# SMTP_PORT=30025 BASE_URL=http://local.sandstorm.io:8080 HTTP_PORT=8080 /opt/tempest/bin/tempest 
time=2023-05-22T16:02:07.406Z level=INFO msg=Listening root-domain=local.sandstorm.io:8080 http-addr=:8080 https-addr=:443

Client:
Firefox 113.0.1 on macOS

When I try to open the home page, I get this message in :

Uncaught (in promise) TypeError: import object field 'env' is not an Object

I'll track this down. I know that you don't have time for this. But I need to know that my crazy setup is close to yours.

@zenhack
Copy link
Owner

zenhack commented May 22, 2023 via email

@troyjfarrell
Copy link
Contributor Author

There is not an associated stack trace. The error message simply says that it was uncaught in a promise.

I replaced /usr/local/go/misc/wasm/wasm_exec.js with /root/tinygo/targets/wasm_exec.js, inspired by tinygo-org/tinygo#448 and got this:
tempest
Then I got a websocket failure, which is probably related to me using HTTP instead of HTTPS.

If that looks like what you've built so far, then we can probably close this issue. (Should we update the README.md to specify that ./configure should get tinygo's wasm_exec.js and not the one in GOROOT?)

@zenhack
Copy link
Owner

zenhack commented May 23, 2023

There's code in make.go that tries to figure out where wasm_exec.js should come from based on whether it's using tinygo or the stock toolchain, so there's still a bug here where that logic doesn't work right on your setup -- so let's leave this open to track that at least.

Re: websocket: I'm doing dev stuff over plain HTTP, so that shouldn't be the issue. Can you show me the exact error message, and any corresponding log messages on the console from the server?

@troyjfarrell
Copy link
Contributor Author

In each case (so far) I had specified a wasm_exec.js, based upon running find /usr/local -type f -name wasm_exec.js, then the same in /root. When I don't specify a wasm_exec.js, a build goes like this:

[root@tempest tempest]# PATH=$PATH:/usr/local/go/bin ./configure --prefix=/opt/tempest --user=tempest --group=tempest --with-go-capnp=/root/go-capnp
[root@tempest tempest]# cat config.json
{
  "User": "tempest",
  "Group": "tempest",
  "Prefix": "/opt/tempest",
  "ExecPrefix": "/opt/tempest",
  "Bindir": "/opt/tempest/bin",
  "Libexecdir": "/opt/tempest/libexec",
  "Localstatedir": "/opt/tempest/var/lib",
  "WithGoCapnp": "/root/go-capnp",
  "WithWasmExecJs": "",
  "TinyGo": true,
  "Args": [
    "--prefix=/opt/tempest",
    "--user=tempest",
    "--group=tempest",
    "--with-go-capnp=/root/go-capnp"
  ]
}[root@tempest tempest]# make
go run internal/make/make.go build
2023/05/24 03:30:54 Building C executable
make[1]: Entering directory '/root/tempest/c'
cc  -I ../_build -std=c11 -Wall -Wextra -MMD -c -o gen-clean-h.o gen-clean-h.c
cc  -o ../_build/gen-clean-h gen-clean-h.o
../_build/gen-clean-h > ../_build/constants.h
cpp -I ../_build filter.s -o ../_build/filter_preproc.s
bpf_asm -c < ../_build/filter_preproc.s > ../_build/bpf_filter.h
cc  -I ../_build -std=c11 -Wall -Wextra -MMD -c -o sandbox-launcher.o sandbox-launcher.c
cc  -o ../_build/tempest-sandbox-launcher sandbox-launcher.o
make[1]: Leaving directory '/root/tempest/c'
2023/05/24 03:30:54 Compiling capnp schema
2023/05/24 03:30:54 Generating go code for "capnp/activity.capnp"
2023/05/24 03:30:54 Generating go code for "capnp/api-session.capnp"
2023/05/24 03:30:54 Generating go code for "capnp/appid-replacements-test.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/appid-replacements.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/collection.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/email.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/external.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/grain.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/hack-session.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/identity.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/ip.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/mime.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/package.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/powerbox.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/sandstorm-http-bridge.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/settings.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/util.capnp"
2023/05/24 03:30:55 Generating go code for "capnp/web-session.capnp"
2023/05/24 03:30:56 Generating go code for "internal/capnp/cookie.capnp"
2023/05/24 03:30:56 Generating go code for "internal/capnp/grain-agent.capnp"
2023/05/24 03:30:56 Generating go code for "internal/capnp/system.capnp"
2023/05/24 03:30:56 failed to find wasm_exec.js
exit status 1
make: *** [Makefile:4: build] Error 1

@zenhack
Copy link
Owner

zenhack commented May 24, 2023

Ah, the first command probably picked up the official toolchain's wasm_exec.js, which doesn't work with TinyGo.

Where is the tinygo executable you're using within your filesystem?

@troyjfarrell
Copy link
Contributor Author

It looks like the websocket error is related to the wasm_exec.js error. Here's what I get when I build with tinygo's wasm_exec.js (everything included for completeness):

[root@tempest tempest]# PATH=$PATH:/usr/local/go/bin ./configure --prefix=/opt/tempest --user=tempest --group=tempest --with-go-capnp=/root/go-capnp --with-wasm_exec.js=/root/tinygo/targets/wasm_exec.js 
[root@tempest tempest]# cat config.json 
{
  "User": "tempest",
  "Group": "tempest",
  "Prefix": "/opt/tempest",
  "ExecPrefix": "/opt/tempest",
  "Bindir": "/opt/tempest/bin",
  "Libexecdir": "/opt/tempest/libexec",
  "Localstatedir": "/opt/tempest/var/lib",
  "WithGoCapnp": "/root/go-capnp",
  "WithWasmExecJs": "/root/tinygo/targets/wasm_exec.js",
  "TinyGo": true,
  "Args": [
    "--prefix=/opt/tempest",
    "--user=tempest",
    "--group=tempest",
    "--with-go-capnp=/root/go-capnp",
    "--with-wasm_exec.js=/root/tinygo/targets/wasm_exec.js"
  ]
}[root@tempest tempest]# make
go run internal/make/make.go build
2023/05/24 03:34:30 Building C executable
make[1]: Entering directory '/root/tempest/c'
cc  -I ../_build -std=c11 -Wall -Wextra -MMD -c -o sandbox-launcher.o sandbox-launcher.c
cc  -o ../_build/tempest-sandbox-launcher sandbox-launcher.o
make[1]: Leaving directory '/root/tempest/c'
2023/05/24 03:34:30 Compiling capnp schema
2023/05/24 03:34:30 Generating go code for "capnp/activity.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/api-session.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/appid-replacements-test.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/appid-replacements.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/collection.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/email.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/external.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/grain.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/hack-session.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/identity.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/ip.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/mime.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/package.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/powerbox.capnp"
2023/05/24 03:34:30 Generating go code for "capnp/sandstorm-http-bridge.capnp"
2023/05/24 03:34:31 Generating go code for "capnp/settings.capnp"
2023/05/24 03:34:31 Generating go code for "capnp/util.capnp"
2023/05/24 03:34:31 Generating go code for "capnp/web-session.capnp"
2023/05/24 03:34:31 Generating go code for "internal/capnp/cookie.capnp"
2023/05/24 03:34:31 Generating go code for "internal/capnp/grain-agent.capnp"
2023/05/24 03:34:31 Generating go code for "internal/capnp/system.capnp"
2023/05/24 03:34:31 Building wasm binary
528K	_build/webui.wasm
2023/05/24 03:34:50 Compiling go executable "sandstorm-import-tool" (static = false)
2023/05/24 03:34:54 Compiling go executable "tempest" (static = false)
2023/05/24 03:34:57 Compiling go executable "tempest-make-user" (static = false)
2023/05/24 03:34:58 Compiling go executable "tempest-grain-agent" (static = true)
2023/05/24 03:34:58 Compiling go executable "test-app" (static = true)
[root@tempest tempest]# make install
go run internal/make/make.go install
2023/05/24 03:35:03 Building C executable
make[1]: Entering directory '/root/tempest/c'
cc  -I ../_build -std=c11 -Wall -Wextra -MMD -c -o sandbox-launcher.o sandbox-launcher.c
cc  -o ../_build/tempest-sandbox-launcher sandbox-launcher.o
make[1]: Leaving directory '/root/tempest/c'
2023/05/24 03:35:03 Compiling capnp schema
2023/05/24 03:35:04 Building wasm binary
2023/05/24 03:35:19 Compiling go executable "sandstorm-import-tool" (static = false)
2023/05/24 03:35:20 Compiling go executable "tempest" (static = false)
2023/05/24 03:35:20 Compiling go executable "tempest-make-user" (static = false)
2023/05/24 03:35:20 Compiling go executable "tempest-grain-agent" (static = true)
2023/05/24 03:35:20 Compiling go executable "test-app" (static = true)
[root@tempest tempest]# SMTP_PORT=30025 BASE_URL=http://local.sandstorm.io:8080 HTTP_PORT=8080 /opt/tempest/bin/tempest 
time=2023-05-24T03:36:37.034Z level=INFO msg=Listening root-domain=local.sandstorm.io:8080 http-addr=:8080 https-addr=:443
time=2023-05-24T03:36:40.860Z level=DEBUG msg="Failed to read session cookie; treating as anonymous" error="http: named cookie not present"
time=2023-05-24T03:37:24.788Z level=ERROR msg="capnp-rpc error" error="transport: stream transport: receive: ws closed: 1001 "
time=2023-05-24T03:37:25.117Z level=DEBUG msg="Failed to read session cookie; treating as anonymous" error="http: named cookie not present"

I believe that the capnp-rpc error shows up because of the syscall/js.finalizeRef not implemented that I'm seeing in the browser console:
tempest-console
It's not just Firefox, either. Here's Safari doing the same:
tempest-safari

@troyjfarrell
Copy link
Contributor Author

Ah, the first command probably picked up the official toolchain's wasm_exec.js, which doesn't work with TinyGo.

Where is the tinygo executable you're using within your filesystem?

(Yes, I'm working as root in a dedicated-to-tempest VM.)

I checked out the tinygo repository to /root/tinygo, then installed it (make install) after building it. This put the executables in GOBIN (/usr/local/go/bin) but did not put wasm_exec.js anywhere:

[root@tempest tempest]# which tinygo
/usr/local/go/bin/tinygo
[root@tempest tempest]# find /usr/local/go -type f -name wasm_exec.js
/usr/local/go/misc/wasm/wasm_exec.js  
[root@tempest tempest]# sha256sum /usr/local/go/misc/wasm/wasm_exec.js /root/tinygo/targets/wasm_exec.js 
da4261f1bf0918d28f2bffa2ec93435d3507e2f1053b61eaa5f8d4d1de5f1daa  /usr/local/go/misc/wasm/wasm_exec.js
131f6acc9d9f0ed8276dcc2d19c229f2f980cc099160ea646a1508bf8d2af3c2  /root/tinygo/targets/wasm_exec.js

@zenhack
Copy link
Owner

zenhack commented May 24, 2023

Ok, that makes sense then. I think the most we could do on the wasm_exec.js front is perhaps a more explicit error message, but I think this is working as intended then -- you didn't have the file installed, not much else for it to do.

tinygo-org/tinygo#1140 looks relevant to those errors, and I'm skeptical that it's related to the disconnects; sounds like it could cause a memory leak but shouldn't otherwise cause problems.

Just to be clear, does the UI appear to be working? The log message is to be expected when a client disconnects, (whenever you close the tab if nothing else) so it doesn't necessarily mean something's broken if there aren't other issues.

@zenhack
Copy link
Owner

zenhack commented May 24, 2023

Just double-checked: I do see those errors when I build with TinyGo, but I'm not getting disconnects.

@troyjfarrell
Copy link
Contributor Author

Perhaps it is working… I can log in with a dev account. Uploading test-app gives me this message at the bottom of the browser: util.capnp:ByteStream.write: external.capnp:UserSession.installPackage: call on null client and these messages in the browser console:

listPackages(): external.capnp:UserSession.listPackages: call on null client [wasm_exec.js:268:19]
test-app 6622298 ReadableStreamDefaultReader { closed: Promise { "pending" } } [wasm_exec.js:362:37]

There are (surprisingly) no messages in the terminal. The test-app never appears under the app list, but maybe that's not written yet.

So, maybe it's working? Either way, we can probably close this issue.

@zenhack
Copy link
Owner

zenhack commented May 24, 2023

Does your user have the user role (See "Creating Users" in the README)? If not, you won't be able to install apps, but the UI is still there for it; obviously at some point we'll want to hide that if you don't have the authority to use it. And there are some known issues, namely #11 and #13.

But yeah, I think we can close this.

@zenhack zenhack closed this as completed May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants