Skip to content
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

Broadcastable.broadcast() does not have timeout #1395

Closed
lyi2012 opened this issue Dec 6, 2013 · 5 comments
Closed

Broadcastable.broadcast() does not have timeout #1395

lyi2012 opened this issue Dec 6, 2013 · 5 comments

Comments

@lyi2012
Copy link

lyi2012 commented Dec 6, 2013

The following method implementation does not have a timeout and causes the thread hanging forever in case the underneath future does not return as expected.

It will be nice to provide a timeout and potential a re-try logic in this unexpected case.

public Object broadcast() {
    try {
        return b.broadcast(message).get();
    } catch (Exception ex) {
        logger.error("failed to broadcast message: " + message, ex);
    }
    return null;
}
@jfarcand
Copy link
Member

jfarcand commented Dec 6, 2013

Use for `broadcaster.broadcast(..) retuns a Future, so use the appropriate .get(). Is it a method in Atmosphere you are referring to?

@jfarcand jfarcand closed this as completed Dec 6, 2013
@lyi2012
Copy link
Author

lyi2012 commented Dec 8, 2013

Hey, Jeanfrancois,

This is an Atmosphere method, but you are right, you did not use it internally in the latest code. I happen to find this public method and used it in my implementation, and did cause thread congestion. Just think it will be nice to remove this since another person like me may also run into the same issue.

@jfarcand
Copy link
Member

jfarcand commented Dec 9, 2013

I would be interested to learn how this is causing thread congestion...noirmally the thread will be unlocked once the message has been delivered.

@lyi2012
Copy link
Author

lyi2012 commented Dec 21, 2013

Just noticed your comment here. A wild guess, should the "future" member be
volatile?

public static final class Entry {

    public Object message;

    public Object multipleAtmoResources;

    public BroadcasterFuture<?> future;

    public boolean writeLocally;

    public Object originalMessage;

Based on the JVM threading model, both threads have a reference to an Entry
object, enqueuing thread sets the "future" member, but the dequeuing
thread may still read it as null, if that happens, the following logic will
be skipped, countdown will never happen.

protected void entryDone(final BroadcasterFuture<?> f) {

    notifyBroadcastListener();

    if (f != null) f.done();

}

On Mon, Dec 9, 2013 at 7:10 AM, Jeanfrancois Arcand <
notifications@github.com> wrote:

I would be interested to learn how this is causing thread
congestion...noirmally the thread will be unlocked once the message has
been delivered.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1395#issuecomment-30139188
.

@lyi2012
Copy link
Author

lyi2012 commented Dec 21, 2013

Never mind, it is a blockingqueue in the middle. But I suspect the initial countdown number might be an issue, it is based on the resources.size(). Can it be different from the actual countdowns?

See the code from 1.0.18,

public <T> Future<T> broadcast(T msg, AtmosphereResource r) {

    if (destroyed.get()) {
        logger.debug(DESTROYED, getID(), "broadcast(T msg, AtmosphereResource r");
        return futureDone(msg);
    }

    start();
    Object newMsg = filter(msg);
    if (newMsg == null) return futureDone(msg);

    BroadcasterFuture<Object> f = new BroadcasterFuture<Object>(newMsg, resources.size());
    dispatchMessages(new Entry(newMsg, r, f, msg));
    return f;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants