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

Lyra throws AlreadyClosedException calling isOpen on a closed channel #58

Open
jaguililla opened this issue Apr 11, 2016 · 1 comment
Open
Labels

Comments

@jaguililla
Copy link

Lyra throws AlreadyClosedException calling isOpen on a closed channel

@jhalterman jhalterman added the bug label Apr 11, 2016
@DimaGolomozy
Copy link

What if RetryableResource#handleCommonMethods will return Object and not void, and add the common method "isOpen" with a return value

Object handleCommonMethods(Object delegate, Method method, Object[] args) throws Throwable {
    if ("abort".equals(method.getName()) || "close".equals(method.getName())) {
      try {
        Reflection.invoke(delegate, method, args);
        return true;
      } finally {
        closed = true;
        afterClosure();
        interruptWaiters();
      }
    } else if ("isOpen".equals(method.getName()))
      return Reflection.invoke(delegate, method, args);
    else if ("addShutdownListener".equals(method.getName()) && args[0] != null)
      shutdownListeners.add((ShutdownListener) args[0]);
    else if ("removeShutdownListener".equals(method.getName()) && args[0] != null)
      shutdownListeners.remove((ShutdownListener) args[0]);
    return null;
  }

and in the ChannelHandler#invoke method:

@Override
  public Object invoke(Object ignored, final Method method, final Object[] args) throws Throwable {
    Object result = handleCommonMethods(delegate, method, args);
    if (result != null)
        return result;
    if (closed && method.getDeclaringClass().isAssignableFrom(Channel.class))
      throw new AlreadyClosedException(delegate.getCloseReason());
.......

It seems to work, and handles the isOpen() after close().
Also, handles calling close() after a close() throws en exception.
But, I cant change the ChannelHandlerTest#shouldThrowOnAlreadyClosedChannelInvocation to throw the exception.

any ideas?

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

No branches or pull requests

3 participants