-
Notifications
You must be signed in to change notification settings - Fork 29
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
VertxExecutionContext issue #148
Comments
Looking... |
@Narigo I've started mysql locally and run the tests, and all I see is: https://gist.github.com/galderz/f87aabb3453f6ce46d8b |
I'm running mysql on localhost, on port 3306. |
@Narigo I think there's a mismatch between what you are trying to do and what Vert.x does. Let me explain. The whole point of the The problem that you are having is that you're asking to access the execution context of vert.x when you are running in a |
Hi, I'm using vertx and scala for a rest api. My rest api is calling a service returning a future. I've looked at the code and I'm stuck on the latest VertxExecutionContext change: Firstthe old code was doing this: vertx.runOnContext(runnable.run()) This looks suspicious: First, the runnable will run, then the function Thenthe fix, changes it by running the runnable directly, which means that we won't switch to the vertx event loop, and that should be the purpose of this code. Do I understand this code correctly ? If so, A basic fix would be: override def execute(runnable: Runnable): Unit =
vertx.runOnContext(new Handler[Void] {
override def handle(v: Void): Unit = { runnable.run() }
} Can you confirm? Thanks. |
@jfrabaute I think it depends who has created the future. If the future is created from within Vert.x, then the thread will already be a Vert.x thread and hence we don't need to call Did you try out your solution? |
Yes we implemented this and it helped remove the flakiness in our CI in our environment. |
Executing vertx.runOnContext() from a non Vert.x thread will not cause the action to be run on a new context, not on the context of the verticle (which is what you want). If you think about it, how is Vert.x supposed to know which verticle you're referring to with just vertx.runOnContext(). The correct way to do this is in two steps:
myContext.runOnContext(...) |
@purplefox : You're right, my fix is using the context of the verticle that I'm passing when I create the ExecutionContext. // The returned execution context will ensure the future will be executed
// in the vertx event loop
def getExecutionContext(context: Context, logger: Logger) = {
new ExecutionContext {
override def reportFailure(t: Throwable): Unit =
logger.error("Error executing Future in VertxHelper.getExecutionContext", t)
override def execute(runnable: Runnable): Unit =
context.runOnContext(new Handler[Void] {
override def handle(v: Void): Unit = {
runnable.run()
}
})
}
} I'm calling this method in the verticle, passing the current vertx context, and assign it to an implicit, so the futures will automatically use this execution context. @galderz If the future is created within vertx (specific case), you're right that there is an extra method call, and extra switching to thread pools, etc. But it should still works, and works in the general case, as the current version right now does not work in the general case but only in the specific case. object SameExecutionContext extends ExecutionContext {
override def reportFailure(t: Throwable): Unit =
logger.error("Error executing Future in VertxHelper.getExecutionContext", t)
override def execute(runnable: Runnable): Unit = runnable.run()
} This can be used like this (still pseudo-code): import ...SameExecutionContext
class ... extends Verticle {
...
futureThaRunsInTheVertxContext.andThen({ case r => println(r) })(SameExecutionContext)
...
} |
@galderz BTW, I was partially wrong in my initial comment. The old version was correct. I didn't check carefully the signature of your method, and passing Sorry about that. |
@galderz I get errors when trying to run the tests here. If you want to check these out, you'll need a MySQL and/or PostgreSQL installed and see the relevant tests that pass but throw errors. The relevant branch is this:
https://github.com/vert-x/mod-mysql-postgresql/tree/execution-context-bug
Check out
AsyncConnectionPool
- this is where I get theExecutionContext
.And here is a gist of the test output, maybe it helps already:
https://gist.github.com/Narigo/8739a91c014f69c55846
The text was updated successfully, but these errors were encountered: