-
Notifications
You must be signed in to change notification settings - Fork 2.1k
make sure after resume we just deliver one message at one moment #5525
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
base: 4.x
Are you sure you want to change the base?
make sure after resume we just deliver one message at one moment #5525
Conversation
9d8836e
to
bdf86b3
Compare
@@ -171,7 +158,7 @@ protected void dispatch(Message<T> msg, ContextInternal context, Handler<Message | |||
if (handler == null) { | |||
throw new NullPointerException(); | |||
} | |||
context.emit(msg, handler); | |||
context.dispatch(msg, handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was reverted as it had a side effect:
after resume we were received many messages even we paused again during the first message processing.
@@ -183,8 +170,8 @@ private void deliver(Handler<Message<T>> theHandler, Message<T> message) { | |||
|
|||
private synchronized void checkNextTick() { | |||
// Check if there are more pending messages in the queue that can be processed next time around | |||
if (!pending.isEmpty() && demand > 0L) { | |||
context.nettyEventLoop().execute(() -> { | |||
if (demand > 0L && !pending.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I flip here so the demand evaulated first
if (!pending.isEmpty() && demand > 0L) { | ||
context.nettyEventLoop().execute(() -> { | ||
if (demand > 0L && !pending.isEmpty()) { | ||
context.executor().execute(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we should schedult the task for the next tick on the context thread (so we have no 2 thread dispatching a message at the same moment).
In the past we had a scenario like:
- received
- pause
- resume
- received + paused
- received ?!
so after we resume we had sometimes got two messages even in the 1st on we said already we don't want to have more right now.
} | ||
if (pending.size() < maxBufferedMessages) { | ||
pending.add(message); | ||
checkNextTick(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method simplified a lot and here we always just put it in hte pending (if the buffer not full yet of course) and send a tick (that will decied if we need to do anything right now or not)
as the tick evaulation happen on the contex thread we are safe (single threaded)
98dc54c
to
a2860aa
Compare
a2860aa
to
e93ab84
Compare
…tricks could be updatedy
@@ -1401,7 +1401,6 @@ public void testUnregisterConsumerDiscardPendingMessages() { | |||
eb.send(ADDRESS1, "val1"); | |||
Context ctx = Vertx.currentContext(); | |||
ctx.runOnContext(v -> { | |||
consumer.resume(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was in the past executed on eventloop thread on the context... now this is executed on the context thread (in case we area lready on it it will not schedule new job, in case we are on another thread it will schedule an async job.
in short:
now this is executed here so the logic below was not anymore fine as this call wipe out sync the pending msgs
if (!pending.isEmpty() && demand > 0L) { | ||
context.nettyEventLoop().execute(() -> { | ||
if (demand > 0L && !pending.isEmpty()) { | ||
context.execute(__ -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we do execute the resume/fetch from the context thread so we do not have situations when we call resume and the same time we do receive a msg and we get 2msgs (on on the context thread and one on eventloop thread)
} | ||
theHandler = handler; | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was also not 100% right, when we do discard msg we should return with false to have that in the metrics
Motivation:
I had a change recently in 4.5.13 (not a lucky number)
After upgrading to this version we have noticed after resume we do receive more than one message at one moment.
First I extended the test to reproduce the case... and after that I done the prod code change.
Conformance:
You should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines