vert-x3 / vertx-config

Vert.x Configuration Service
Apache License 2.0
54 stars 64 forks source link

ConfigRetriever possibly responsible for 'Multi threaded access request' failures #113

Closed UglyHobbitFeet closed 4 years ago

UglyHobbitFeet commented 4 years ago

I have started to try and use the config retriever to read in a properties file for vertx. The code looks like below:

import { ConfigRetriever } from '@vertx/config';
import { ConfigStoreOptions, ConfigRetrieverOptions } from '@vertx/config/options';

const fileStore = new ConfigStoreOptions().setType('file')
  .setFormat('properties')
  .setConfig({ 'path': '/foo/bar.properties' });
const configRetrieverOptions = new ConfigRetrieverOptions().addStore(fileStore);
const retriever = ConfigRetriever.create(vertx, configRetrieverOptions);

retriever.getConfig((futureResult, json_err) => {
  if (json_err != null) {
    console.error(json_err);
    return;
  }
  futureResult.onSuccess((result) => {
    console.log('From Future:', JSON.stringify(result)));

    const server = vertx.createHttpServer().requestHandler(app).listen(parseInt(result.port), result.host);
  );}

});

However, when I launch the VM (npm run build;npm start;) I start seeing the following two messages in the console:

Unhandled Exception caused by java.lang.IllegalStateException: Multi threaded access 
requested by thread Thread(vert.x-eventloop-thread-0,5,main] but is not allowed for 
language(s) js

and

Unhandled Exception caused by java.lang.IllegalStateException: Multi threaded access 
requested by thread Thread(vert.x-worker-thread-9,5,main] but is not allowed for 
language(s) js

both with the same stacktrace of

 at  com.oracle.truffle.polyglot.PolyglotContextImp.throwDeniedThreadAccess(
  PolyglotContextImpl.java:649
...(other com.oracle.truffle and org.graalvm.compiler.truffle.runtime traces omitted)
at io.vertx.core.json.JsonObject.getBoolean(JsonObject.java:429)
at io.vertx.config.impl.spi.PropertiesConfigProcessor.process(
  PropertiesConfigProcessor.java:61)
at io.vertx.config.impl.ConfigurationProvider.lambda$get$1(
  ConfigurationProvider.java:71)
..etc

FYI my current workaround is to use

const content = vertx.fileSystem().readFileBlocking(file).toString();

and to manually parse the file for properties. Doing this causes no multi-threading issues.

FWIW I'm on:

Is it possibly linked to https://github.com/graalvm/graaljs/issues/59, and if so, what would the fix be?

pmlopes commented 4 years ago

This is a known issue with executeBlocking and graaljs. Currently I have no fix for it as it requires a different way to schedule blocking tasks without calling back to the original thread.

pmlopes commented 4 years ago

Hi, I've just test this with:

import { ConfigRetriever } from '@vertx/config';
import { ConfigStoreOptions, ConfigRetrieverOptions } from '@vertx/config/options';

const fileStore = new ConfigStoreOptions()
  .setType('file')
  .setFormat('properties')
  .setConfig({ 'path': 'foobar.properties' });

const retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(fileStore));

retriever.getConfig(ar => {
  if (ar.failed()) {
    console.trace(ar.cause());
  } else {
    console.log('From Future:', JSON.stringify(ar.result()));
  }
});

And my package.json:

{
  "name": "config",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "es4x test index.test.js",
    "postinstall": "es4x install",
    "start": "es4x"
  },
  "dependencies": {
    "@vertx/core": "^3.9.0",
    "@vertx/config": "^3.9.0"
  }
}

With the following properties:

key=value

And cannot reproduce the issue anymore. I'll close it and mark it as fixed.

UglyHobbitFeet commented 4 years ago

Good to know! For what it's worth, I ran into a bunch of these threading errors when using the vertx-mongo 3.8.5 yesterday. I can try with 3.9.0/0.11 and see if things are different

On Thu, Apr 2, 2020 at 5:25 AM Paulo Lopes notifications@github.com wrote:

Closed #113 https://github.com/vert-x3/vertx-config/issues/113.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vert-x3/vertx-config/issues/113#event-3191328547, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALBDS7QJVWUYZFOBFB4BOITRKRKZFANCNFSM4K4GWA4A .

UglyHobbitFeet commented 4 years ago

The issue (to some degree) still exists and I opened a ticket in vertx/mongo https://github.com/vert-x3/vertx-mongo-client/issues/224