Skip to content

fix deadlock in testStreamAckDeadlineUpdate #1581

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

Merged
merged 2 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import com.google.cloud.pubsub.spi.v1.MessageReceiver;
import com.google.cloud.pubsub.spi.v1.Subscriber;
import com.google.cloud.pubsub.spi.v1.SubscriberClient;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.PushConfig;
import com.google.pubsub.v1.SubscriptionName;
Expand All @@ -44,9 +43,10 @@ public static void main(String... args) throws Exception {
MessageReceiver receiver =
new MessageReceiver() {
@Override
public ListenableFuture<MessageReceiver.AckReply> receiveMessage(PubsubMessage message) {
public void receiveMessage(
PubsubMessage message, SettableFuture<MessageReceiver.AckReply> response) {
System.out.println("got message: " + message.getData().toStringUtf8());
return Futures.immediateFuture(MessageReceiver.AckReply.ACK);
response.set(MessageReceiver.AckReply.ACK);
}
};
Subscriber subscriber = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.ReceivedMessage;
import java.util.ArrayList;
Expand Down Expand Up @@ -278,11 +279,13 @@ public void processReceivedMessages(List<com.google.pubsub.v1.ReceivedMessage> r
for (ReceivedMessage userMessage : responseMessages) {
final PubsubMessage message = userMessage.getMessage();
final AckHandler ackHandler = acksIterator.next();
final SettableFuture<AckReply> response = SettableFuture.create();
Futures.addCallback(response, ackHandler);
executor.submit(
new Runnable() {
@Override
public void run() {
Futures.addCallback(receiver.receiveMessage(message), ackHandler);
receiver.receiveMessage(message, response);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.cloud.pubsub.spi.v1;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.google.pubsub.v1.PubsubMessage;

/** This interface can be implemented by users of {@link Subscriber} to receive messages. */
Expand All @@ -34,11 +34,10 @@ enum AckReply {
*/
NACK
}

/**
* Called when a message is received by the subscriber.
*
* @return A future that signals when a message has been processed.
* Called when a message is received by the subscriber. The implementation must arrange for {@code
* reponse} to be set after processing the {@code message}.
*/
ListenableFuture<AckReply> receiveMessage(PubsubMessage message);
void receiveMessage(PubsubMessage message, SettableFuture<AckReply> response);

This comment was marked as spam.

This comment was marked as spam.

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
* <pre><code>
* MessageReceiver receiver = new MessageReceiver() {
* &#64;Override
* public ListenableFuture&lt;AckReply&gt; receiveMessage(PubsubMessage message) {
* public void receiveMessage(PubsubMessage message, SettableFuture&lt;AckReply&gt; response) {
* // ... process message ...
* return Futures.immediateFuture(AckReply.ACK);
* return response.set(AckReply.ACK);
* }
* }
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.PullResponse;
Expand Down Expand Up @@ -115,23 +114,20 @@ void waitForExpectedMessages() throws InterruptedException {
}

@Override
public ListenableFuture<AckReply> receiveMessage(PubsubMessage message) {
public void receiveMessage(PubsubMessage message, SettableFuture<AckReply> response) {
if (messageCountLatch.isPresent()) {
messageCountLatch.get().countDown();
}
SettableFuture<AckReply> reply = SettableFuture.create();

if (explicitAckReplies) {
try {
outstandingMessageReplies.put(reply);
outstandingMessageReplies.put(response);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
} else {
replyTo(reply);
replyTo(response);
}

return reply;
}

public void replyNextOutstandingMessage() {
Expand Down