Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

async calls from a web worker leads to incorrect and duplicate responses #7466

Copy link
Copy link
Open
@jritts

Description

@jritts
Issue body actions

Making asynchronous calls from a worker procedure will lead to incorrect and duplicate responses being sent to the main thread.

For example:

// worker
void workerProc(int8_t* data, int size) {
   myAsyncLoadFromIndexDB( [](void* result, int resultSize) {
       emscripten_worker_respond_provisionally(result, resultSize);
   }, data);
}
// main
emscripten_call_worker(myWorker, "workerProc", "name", 5, nameCallback, null);
emscripten_call_worker(myWorker, "workerProc", "addr", 5, addrCallback, null);

...when run, the callback "addrCallback" will be called for both responses.

The problem is that an emscripten worker uses a single global variable, workerCallbackId, to map incoming to outgoing messages. If you post two consecutive messages to the worker, workerCallbackId will get overwritten by the second call before either of the worker's async calls have finished, so they will both end up using the second callback function and user argument.

We fixed this in our own code by modifying the worker prototype and emscripten_worker_respond* functions to take an additional parameter, 'int callbackId', and it's the responsibility of the worker invocation to pass that index through to its response.

This isn't a backwards compatible fix of course -- any suggestion for a better approach that I could implement and submit?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.