Coder Social home page Coder Social logo

Comments (7)

mathetake avatar mathetake commented on May 28, 2024

please provide the reproducer, otherwise we can't verify

from wazero.

mathetake avatar mathetake commented on May 28, 2024

closing until you give us the minimal repro. Note that executing a module instance concurrently is inherently unsafe and not possible unless you use the threading proposal enabled + your binary is compiled in that way.

from wazero.

martinlakov avatar martinlakov commented on May 28, 2024

As described in this comment - a compilation engine is getting re-used/shared between runtimes.

The wazevo engine comes with an internal map named compiledModules. When creating runtimes & compiling modules happens concurrently - a race condition occurs with accessing the said map. This happens in here

from wazero.

martinlakov avatar martinlakov commented on May 28, 2024

I'd be glad to provide example(s), propose a fix etc. Just want to see this one getting resolved 😊

from wazero.

martinlakov avatar martinlakov commented on May 28, 2024

A bit of background to the story - issue has been observed while working on a high-level library that steps on top of wazero and takes care to hide away complexity associated with working with the linear memory etc. This one - we plan to open-source as soon we have the APIs somewhat final.

from wazero.

martinlakov avatar martinlakov commented on May 28, 2024

@mathetake - update of my previous comment (was on my phone, on my way to work)

As described in this comment - a compilation engine is getting re-used/shared between runtimes.

The wazevo engine comes with an internal map named compiledModules. When creating runtimes & compiling modules happens concurrently - a race condition occurs with accessing the said map. This happens like so:

As the "callstack" suggests - there's no logic to govern access to the said map and the said map is not thread-safe. As a result - a race condition occurs as soon as you try and use a single cache instance among multiple runtime instances and you try to load/execute modules concurrently.

It is evident that we're talking about a bug in here. If you take a look at the implementation of CompiledModuleCount for wazevo (see: here) - read-only access to the said map is governed appropriately.

from wazero.

martinlakov avatar martinlakov commented on May 28, 2024

A potential fix for the problem is to create a "private" function to check if a module has been compiled already. Something like:

func (e *engine) isCompiled(m *wasm.Module) bool {
	e.mux.RLock()
	defer e.mux.RUnlock()

	_, ok := e.compiledModules[m.ID]
	return ok
}

and replace the direct access to the map in here with calling the said function.

from wazero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.