-
Notifications
You must be signed in to change notification settings - Fork 251
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
golang os.Environ()
leading to panic: runtime error: nil pointer dereference
#1259
Comments
I also see this with The equivalent Rust API ( |
I just verified this with TinyGo 0.27.0. My guess is that there's something about how TinyGo compiles |
Update: I can confirm that calling diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index f6756c8..319d6ad 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -20,7 +20,7 @@ use std::{
use anyhow::Result;
use crossbeam_channel::Sender;
use tracing::instrument;
-pub use wasmtime::{self, Instance, Module, Trap};
+pub use wasmtime::{self, Extern, Instance, Module, Trap};
pub use wasmtime_wasi::I32Exit;
use wasmtime_wasi::WasiCtx;
@@ -267,7 +267,13 @@ impl<T: Send + Sync> InstancePre<T> {
/// Instantiates this instance with the given [`Store`].
#[instrument(skip_all)]
pub async fn instantiate_async(&self, store: &mut Store<T>) -> Result<Instance> {
- self.inner.instantiate_async(store).await
+ let instance = self.inner.instantiate_async(&mut *store).await?;
+
+ if let Some(Extern::Func(func)) = instance.get_export(&mut *store, "_start") {
+ func.call_async(store, &[], &mut []).await?;
+ }
+
+ Ok(instance)
}
} Not sure yet if that's an appropriate way to address this, though. |
I'm a little wary of adding a call to |
See wasi-libc's implementation of |
Is it worth raising this with the TinyGo folks? That is, should libc be fully up and working even if only (I seem to recall a similar (though bigger) issue with AssemblyScript, where they relied on things entering through @voigt It seems like the answer might be that this isn't working at least in the short term - is this a blocker for you, or does |
Seems relevant: tinygo-org/tinygo#2735 |
I've been digging through the tinygo source and these errors still don't make sense to me, but one hack to try might be to call |
@lann I gave that a quick try and it didn't seem to help I'm afraid (though never discount the possibility of user error). |
I hit this a while back also. @lann I tried your suggestion and had the same results |
@itowlson I worked on some PoCs, comparing Spin implementations in Rust and Go. Therefore I wouldn't consider it a blocker. This is precisely the kind of the reason I was doing it :) Thank you, all, for quickly triaging and sorting the issue! |
I am running into a similar issue when trying to use github-sdk into a Spin app. In the sdk there is a private map. It seems like when trying to use this sdk with Spin, this map has 0 entries. Following code seems to work fine with could someone please confirm if this is related to the original issue or should I report a new issue for tracking this
|
@rajatjindal It's an unrelated isssue. But... I couldn't reproduce this working in wasmtime but the issue is refection not being fully implemented in tinygo. |
Hey,
Wanted to write a golang program that reads environment variables and stumbled upon a nasty
nil pointer dereference
. I was able to isolate the problem toos.Environ()
.The crash only happens in
spin
. Compiling to wasm and executing withwasmtime
works as expected.main.go
Leading to
Doing the same in
tinygo
&& executing inwasmtime
works:main.go
$ tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go $ wasmtime main.wasm 2023/03/11 14:37:11 os.Environ() 2023/03/11 14:37:11 []
Versions
Would be great to hear an expert opinion to understand whether
os.Environ()
is supposed to work... :)The text was updated successfully, but these errors were encountered: