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

Keepalive thread's interrupt signal may be catched when it is sleeping #283

Closed
gatesking opened this issue Nov 29, 2016 · 2 comments
Closed

Comments

@gatesking
Copy link
Contributor

gatesking commented Nov 29, 2016

In Keepalive.java:

try {
            while (!isInterrupted()) {
                final int hi = getPositiveInterval();
                if (conn.getTransport().isRunning()) {
                    log.debug("Sending keep-alive since {} seconds elapsed", hi);
                    doKeepAlive();
                }
                **Thread.sleep(hi * 1000);**
            }
        } catch (Exception e) {
            // If we weren't interrupted, kill the transport, then this exception was unexpected.
            // Else we're in shutdown-mode already, so don't forcibly kill the transport.
            if (!isInterrupted()) {
                conn.getTransport().die(e);
            }
        }

when keepalive interrupt is called in ConnectionImpl.notifyError, the interrupt signal may be catched by Thread.sleep, as a result, it will still go into conn.getTransport().die(e).
I suggest catch interrupt signal will be better, am I right?

try {
            while (!isInterrupted()) {
                final int hi = getPositiveInterval();
                if (conn.getTransport().isRunning()) {
                    log.debug("Sending keep-alive since {} seconds elapsed", hi);
                    doKeepAlive();
                }
                Thread.sleep(hi * 1000);
            }
        } **catch (InterruptedException e) {
                // do nothing
        }** catch (Exception e) {
            // If we weren't interrupted, kill the transport, then this exception was unexpected.
            // Else we're in shutdown-mode already, so don't forcibly kill the transport.
            if (!isInterrupted()) {
                conn.getTransport().die(e);
            }
        }

Thanks!

@hierynomus
Copy link
Owner

hierynomus commented Nov 29, 2016 via email

@hierynomus
Copy link
Owner

Merged #284, thanks!

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

No branches or pull requests

2 participants