Comments (3)
Also note that if instead of:
c2 := getCompiledModule(ctx, r)
c1.Close(ctx)
doAdd(ctx, r, c2)
I change the order and do this:
c1.Close(ctx)
c2 := getCompiledModule(ctx, r)
doAdd(ctx, r, c2)
Then it works - but there's a problem with that approach. In my real app I have these compiled modules saved in a map and accessed by an independent goroutine. So between closing c1 and loading c2, there's no compiled module ready to instantiate.
I think perhaps something in the runtime instance is stateful with regard to all modules? Thinking it might be the module name, I tried giving them different module names in their configurations - but with the same results.
from wazero.
the underlying issue is that both compiled modules resolve to the same hash
wazero/internal/wasm/module.go
Lines 168 to 170 in 5c70d8b
so when you close the first we are also deleting the cache entry:
wazero/internal/engine/compiler/engine_cache.go
Lines 18 to 26 in 99c057b
a workaround is setting up a disk cache, this way when the key is deleted from the in-memory cache we will reload it from disk; e.g.:
ctx := context.Background()
cc, _ := wazero.NewCompilationCacheWithDir("/tmp/wazerocache")
r := wazero.NewRuntimeWithConfig(ctx,
wazero.NewRuntimeConfig().WithCompilationCache(cc))
this only occurs when you are closing and reloading a module with the same hash; if the module has been actually updated, then the hash should change, and deletion should not affect its cache entry.
from wazero.
// Works first time no problem
c1 := getCompiledModule(ctx, r)
doAdd(ctx, r, c1)
// Fails second time because first module is closed - why?
c2 := getCompiledModule(ctx, r)
c1.Close(ctx) // I want to close c1, but keep c2 ready for use
yeah this patter simply doesn't make sense - why when the binary if the same you want to close the previous one? basically the variable c1 and c2 points to exactly the same objects and you essentially closed the compiled object.
from wazero.
Related Issues (20)
- Read directory bug ? HOT 1
- Wasm GC HOT 3
- Dynamically load WASM files HOT 1
- ` fd_fdstat_set_flags` truncates file HOT 1
- [WASI] `fd_fdstat_set_flags` with `fdflags::append` resets fd offset HOT 1
- `fd_filestat_set_size` wraps instead of error on large file size
- Inaccurate clock resolution in WASI `clock_res_get` HOT 3
- Feature Request: Rust tokio async interoperability through pollOneOff HOT 20
- flaky test: ExampleCoreFeaturesThreads HOT 2
- flaky test: internal/engine/wazevo.TestE2E on amd64 HOT 2
- flaky test: wasi_snapshot_preview1/wasi_stdlib_unix_test Test_NonblockingFile
- flaky test: TestFileCache_{compiler, wazevo} HOT 12
- Complex Types using WIT Supported HOT 2
- flaky test: TestPoll_Windows/poll_should_wait_for_the_given_duration
- Expose fsConfig.WithSysFSMount for custom writable FS support HOT 4
- How to concurrent call one instance's export function? HOT 2
- dirfs.OpenFile can return EEXIST even if that is not defined FS.OpenFile in the interface documentation HOT 4
- dirfs.OpenFile can return ENAMETOOLONG even if that is not defined FS.OpenFile in the interface documentation HOT 3
- flaky test: Test_pathOpen_Errors/trailing_slash_on_file on Windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wazero.