reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
881 stars 75 forks source link

Multiple verticle instances generate bad context exceptions from graalvm when loading modules from common npm packages #579

Closed chefhoobajoob closed 2 years ago

chefhoobajoob commented 2 years ago

See here for a reproducer using rxjs to illustrate. If two or more verticle instances are deployed that each use one or more large/modularized-enough npm packages in common, then the second verticle instance to attempt to load one of these packages' modules will result in a graalvm PolyglotException citing either a multi-threaded access or wrong context assertion error.

Reproducible on es4x 0.17.0, vertx 4.2.4

pmlopes commented 2 years ago

As @chefhoobajoob noted graalvm file system is expected to be set per graal context, while we share a global FS. This sharing may be the root cause of the wrong thread exception.

We should rewrite the filesystem implementation to use a correct vert.x context as this ensures that we also are on the right thread most of the times.