Skip to content

Conversation

@Tim-Brooks
Copy link
Contributor

@Tim-Brooks Tim-Brooks commented Jan 9, 2019

Closing a channel using TLS/SSL requires reading and writing a
CLOSE_NOTIFY message (for pre-1.3 TLS versions). Many implementations do
not actually send the CLOSE_NOTIFY message, which means we are depending
on the TCP close from the other side to ensure channels are closed. In
case there is an issue with this, we need a timeout. This commit adds a
timeout to the channel close process for TLS secured channels.

As part of this change, we need a timer service. We could use the
generic Elasticsearch timeout threadpool. However, it would be nice to
have a local to the nio event loop timer service dedicated to network needs. In
the future this service could support read timeouts, connect timeouts,
request timeouts, etc. This commit adds a basic priority queue backed
service. Since our timeout volume (channel closes) is very low, this
should be fine. However, this can be updated to something more efficient
in the future if needed (timer wheel). Everything being local to the event loop
thread makes the logic simple as no locking or synchronization is necessary.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

@Tim-Brooks
Copy link
Contributor Author

run gradle build tests 2

@Tim-Brooks Tim-Brooks changed the title Add tls/ssl channel close timeouts Add TLS/SSL channel close timeouts Jan 9, 2019
Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. looks good though. I was pretty confused about the use of ThreadLocal in your description. Maybe you can change that?

}
}

public interface Cancellable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use Runnable instead?


private final PriorityQueue<DelayedTask> tasks = new PriorityQueue<>(Comparator.comparingLong(DelayedTask::getDeadline));

public Cancellable schedule(Runnable task, TimeValue timeValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is trappy, can we only have the scheduleAtRelativeTime method instead?

return scheduleAtRelativeTime(task, System.nanoTime() + timeValue.nanos());
}

public Cancellable scheduleAtRelativeTime(Runnable task, long relativeNanos) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadocs please

* A basic priority queue backed timer service. The service is thread local and should only be used by a
* single nio selector event loop thread.
*/
public class NioTimer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Nio in the name is obsolete?

@Tim-Brooks
Copy link
Contributor Author

run gradle build tests 1

@Tim-Brooks Tim-Brooks merged commit cfa58a5 into elastic:master Jan 9, 2019
@Tim-Brooks Tim-Brooks deleted the implement_timeouts branch January 11, 2019 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants