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

.ready is not resolved or rejected in WebWorker when using Edge #143

Closed
webmaster128 opened this issue Mar 6, 2018 · 2 comments
Closed

Comments

@webmaster128
Copy link
Contributor

webmaster128 commented Mar 6, 2018

Steps to reproduce:

  1. git clone https://github.com/webmaster128/webpack-minimal.git
  2. checkout branch libsodiumjs-webworker (contains an unminified hackable libsodium.js and libsodium-wrappers.js)
  3. yarn install
  4. yarn build
  5. yarn start
  6. open browser at http://localhost:5000
  7. Click button to start WebWorker

Expected: log output contains

[Main thread] waiting for libsodium
[Main thread] libsodium ready
Starting worker …
[Worker] waiting for libsodium
[Worker] libsodium ready

On Edge 16, the output only contains

[Main thread] waiting for libsodium
[Main thread] libsodium ready
Starting worker …
[Worker] waiting for libsodium

When adding the crypto polyfill from @buu700 #46 (comment) (slightly modified to be usable in strict mode) to cryptoworker.js (cryptoworker.js.txt), everything works.

This brings me to two questions:

  1. Why is .ready not rejected when crypto is missing?
  2. Why is a random number generator required before any libsodium function is called? Maybe I just need some Argon2 and do not need a RNG.
@webmaster128
Copy link
Contributor Author

This happens because _sodium_init() never returns in

(function(root) {
  function expose_wrappers(exports, libsodiumModule) {
    "use strict";

    var output_format = "uint8array";

    var libsodium;
    var ready = libsodiumModule.ready.then(function() {
      libsodium = libsodiumModule;
      if (libsodium._sodium_init() !== 0) {
        throw new Error("libsodium was not correctly initialized.");
      }
      // ...

@webmaster128
Copy link
Contributor Author

Arg, unhandled Promise rejections do not throw an error in Edge.

Adding a rejection handler reveals the error:

libsodium.ready
    .then(function(sodium) {
        console.log("[Worker] libsodium ready");
    })
    .catch(function(error) {
        console.log("[Worker] libsodium errored:", error);
    });

leads to

[Worker] libsodium errored: TypeError: Unable to get property 'getRandomValues' of undefined or null reference

which is correct since both window_.crypto and window_.msCrypto are undefined in the worker.

Note to myself: Promise rejections may be silent, depending on the JavaScript environment.

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

1 participant