|
29 | 29 | import org.glassfish.grizzly.http.HttpContent;
|
30 | 30 | import org.glassfish.grizzly.http.HttpRequestPacket;
|
31 | 31 | import org.glassfish.grizzly.impl.FutureImpl;
|
| 32 | +import org.glassfish.grizzly.nio.NIOConnection; |
| 33 | +import org.glassfish.grizzly.nio.SelectorRunner; |
32 | 34 | import org.glassfish.grizzly.ssl.SSLBaseFilter;
|
33 | 35 | import org.glassfish.grizzly.ssl.SSLFilter;
|
34 | 36 | import org.glassfish.grizzly.utils.Futures;
|
@@ -169,20 +171,46 @@ synchronized void initializeAsynchronousTransfer(final FilterChainContext contex
|
169 | 171 | }
|
170 | 172 | this.context = context;
|
171 | 173 | asyncTransferInitiated = true;
|
| 174 | + final Runnable r = new Runnable() { |
| 175 | + @Override |
| 176 | + public void run() { |
| 177 | + try { |
| 178 | + if (requestPacket.isSecure() && |
| 179 | + (getSSLEngine(context.getConnection()) == null)) { |
| 180 | + flushOnSSLHandshakeComplete(); |
| 181 | + } else { |
| 182 | + feeder.flush(); |
| 183 | + } |
| 184 | + } catch (IOException ioe) { |
| 185 | + GrizzlyAsyncHttpProvider.HttpTransactionContext ctx = |
| 186 | + GrizzlyAsyncHttpProvider.getHttpTransactionContext( |
| 187 | + c); |
| 188 | + ctx.abort(ioe); |
| 189 | + } |
| 190 | + } |
| 191 | + }; |
172 | 192 |
|
173 |
| - if (requestPacket.isSecure() && |
174 |
| - (getSSLEngine(context.getConnection()) == null)) { |
175 |
| - flushOnSSLHandshakeComplete(); |
| 193 | + // If the current thread is a selector thread, we need to execute |
| 194 | + // the remainder of the task on the worker thread to prevent |
| 195 | + // it from being blocked. |
| 196 | + if (isCurrentThreadSelectorRunner()) { |
| 197 | + c.getTransport().getWorkerThreadPool().execute(r); |
176 | 198 | } else {
|
177 |
| - feeder.flush(); |
| 199 | + r.run(); |
178 | 200 | }
|
179 |
| - |
180 | 201 | }
|
181 | 202 |
|
182 | 203 |
|
183 | 204 | // --------------------------------------------------------- Private Methods
|
184 | 205 |
|
185 | 206 |
|
| 207 | + private boolean isCurrentThreadSelectorRunner() { |
| 208 | + final NIOConnection c = (NIOConnection) context.getConnection(); |
| 209 | + final SelectorRunner runner = c.getSelectorRunner(); |
| 210 | + return (Thread.currentThread() == runner.getRunnerThread()); |
| 211 | + } |
| 212 | + |
| 213 | + |
186 | 214 | private void flushOnSSLHandshakeComplete() throws IOException {
|
187 | 215 | final FilterChain filterChain = context.getFilterChain();
|
188 | 216 | final int idx = filterChain.indexOfType(SSLFilter.class);
|
@@ -331,7 +359,6 @@ private static void blockUntilQueueFree(final Connection c) {
|
331 | 359 | if (!c.canWrite()) {
|
332 | 360 | final FutureImpl<Boolean> future =
|
333 | 361 | Futures.createSafeFuture();
|
334 |
| - |
335 | 362 | // Connection may be obtained by calling FilterChainContext.getConnection().
|
336 | 363 | c.notifyCanWrite(new WriteHandler() {
|
337 | 364 |
|
|
0 commit comments