diff --git a/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG0.java b/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG0.java index 72f3e2bdb..ec5653245 100644 --- a/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG0.java +++ b/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG0.java @@ -252,7 +252,7 @@ protected void receive_loop(NextFilter next, IoBuffer message) throws SSLExcepti LOGGER.debug("{} receive_loop() - handshake needs task, scheduling", toString()); } - execute_task(next); + schedule_task(next); break; case NEED_WRAP: diff --git a/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG1.java b/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG1.java index 7e2f9f6e9..5fbeeae83 100644 --- a/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG1.java +++ b/mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG1.java @@ -273,7 +273,7 @@ protected void receive_loop(NextFilter next, IoBuffer message) throws SSLExcepti LOGGER.debug("{} receive_loop() - handshake needs task, scheduling", toString()); } - execute_task(next); + schedule_task(next); break; case NEED_WRAP: @@ -774,8 +774,20 @@ protected void forward_writes(NextFilter next) { */ protected void schedule_task(NextFilter next) { if (ENABLE_ASYNC_TASKS && (mExecutor != null)) { - mExecutor.execute(() -> SSLHandlerG1.this.execute_task(next)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("{} schedule_task() - scheduling task", this); + } + mExecutor.execute(() -> { + try { + execute_task(next); + } finally { + forward_writes(next); + } + }); } else { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("{} schedule_task() - scheduling disabled, executing inline", this); + } execute_task(next); } } @@ -787,7 +799,7 @@ protected void schedule_task(NextFilter next) { * * @param next The next filer in the chain */ - synchronized protected void execute_task(NextFilter next) { + protected void execute_task(NextFilter next) { Runnable task; while ((task = mEngine.getDelegatedTask()) != null) { try {