vertx-mongo-client icon indicating copy to clipboard operation
vertx-mongo-client copied to clipboard

Multi threaded access request failures

Open UglyHobbitFeet opened this issue 4 years ago • 2 comments

I get Multi threaded access request failures when using this package. This is an extension of ticket (https://github.com/vert-x3/vertx-config/issues/113) . FWIW I tried with both Vertx 3.8.5 and 3.9.0

Here is the most basic example I can think of to generate it:

function someFunction() {
  const results = [];
  const entries = []; // Generate N number of entries and place them in the array

  // Attempt to run everything in parallel
  await Promise.all(entries.map(async (entry) => {
    if (someBoolean) {
      results.push(await addNewEntry(entry));
    } else if (someOtherBoolean) {
      results.push(await updateEntry(entry));
    } else {
      results.push(await removeEntry(entry));
    }
  }));

 // Everything should resolve before moving forward
 doSomethingWithResults(results);
}

async function addNewEntry(entry) {
  const doc = {
    tons: 'of',
    keys: '!!',
  };
  await insertEntry(doc);
  return SOME_FLAG;
}

async function insertEntry(doc) {
    try {
      mongoClient.insert("myCollection", doc, (res) => {
        if (res.succeeded()) {
          return res.result();
        } else {
          throw new Error(res.cause().getMessage());
        }
      });
    } catch(e) {
      throw new Error(e);
    }
}

// Note - I omitted the update and remove example functions as they are very 
// similar to whats already shown above

The Error I receive is:

Unhandled exception caused by Reason: Multi threaded access requested by thread Thread[Thread-10,5,main] but is not allowed for language(s) js.
        at <js> :=>(myFile.js:117:3646-3736)
        at com.oracle.truffle.polyglot.FunctionProxyHandler.invoke(HostInteropReflect.java:454)
        at com.sun.proxy.$Proxy29.handle(Unknown Source)
        at io.vertx.ext.mongo.impl.MongoClientImpl.lambda$null$12(MongoClientImpl.java:793)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)

If I run everything in sequence instead of parallel I do not get those errors. However that causes lots more waiting for each to resolve in order, which is not what I want.

for (let z=0; z < entries.length; z++) {
    if (someBoolean) {
      results.push(await addNewEntry(entries[z]));
    } else if (someOtherBoolean) {
      results.push(await updateEntry(entries[z]));
    } else {
      results.push(await removeEntry(entries[z]));
    }
}));
doSomethingWithResults(results);

UglyHobbitFeet avatar Apr 02 '20 20:04 UglyHobbitFeet

@UglyHobbitFeet could you prepare a small working example, i can copy paste and look into? I want to trace the issue as it is not clear if it is a vertx context mismatch or a es4x bug

pmlopes avatar Jul 30 '20 19:07 pmlopes

I'm sorry but I don't know how to provide more info than what's already in this ticket. I'm unfamiliar with setting this up in a sandbox that you can access. Hopefully what I've already posted will be enough to go off of

On Thu, Jul 30, 2020 at 3:04 PM Paulo Lopes [email protected] wrote:

@UglyHobbitFeet https://github.com/UglyHobbitFeet could you prepare a small working example, i can copy paste and look into? I want to trace the issue as it is not clear if it is a vertx context mismatch or a es4x bug

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vert-x3/vertx-mongo-client/issues/224#issuecomment-666606488, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALBDS7R344O3LOSTDWUJUF3R6G737ANCNFSM4L23S2PA .

UglyHobbitFeet avatar Aug 03 '20 14:08 UglyHobbitFeet

@pmlopes hi,I ran into the same problem. How is this issue going?

darrenweb avatar Apr 28 '23 08:04 darrenweb

@darrenweb please report this issue to the es4 repository with a small reproducer. Thanks

tsegismont avatar May 03 '23 14:05 tsegismont