View | Details | Raw Unified | Return to bug 62515
Collapse All | Expand All

(-)java/org/apache/catalina/core/StandardService.java (+3 lines)
Lines 458-463 Link Here
458
        synchronized (connectorsLock) {
458
        synchronized (connectorsLock) {
459
            for (Connector connector: connectors) {
459
            for (Connector connector: connectors) {
460
                connector.pause();
460
                connector.pause();
461
                // Close server socket if bindOnInit is false
462
                // Note: bindOnInit test is in AbstractEndpoint
463
                connector.getProtocolHandler().closeServerSocket();
461
            }
464
            }
462
        }
465
        }
463
466
(-)java/org/apache/coyote/AbstractProtocol.java (+6 lines)
Lines 631-636 Link Here
631
    }
631
    }
632
632
633
633
634
    @Override
635
    public void closeServerSocket() {
636
        endpoint.closeServerSocket();
637
    }
638
639
634
    // ------------------------------------------- Connection handler base class
640
    // ------------------------------------------- Connection handler base class
635
641
636
    protected static class ConnectionHandler<S> implements AbstractEndpoint.Handler<S> {
642
    protected static class ConnectionHandler<S> implements AbstractEndpoint.Handler<S> {
(-)java/org/apache/coyote/ProtocolHandler.java (+7 lines)
Lines 101-106 Link Here
101
101
102
102
103
    /**
103
    /**
104
     * Close the server socket (to prevent further connections) if bindOnInit is
105
     * {@code false} but do not perform any further shutdown.
106
     */
107
    public void closeServerSocket();
108
109
110
    /**
104
     * Requires APR/native library
111
     * Requires APR/native library
105
     *
112
     *
106
     * @return <code>true</code> if this Protocol Handler requires the
113
     * @return <code>true</code> if this Protocol Handler requires the
(-)java/org/apache/tomcat/util/net/AbstractEndpoint.java (+23 lines)
Lines 1206-1211 Link Here
1206
        } else return -1;
1206
        } else return -1;
1207
    }
1207
    }
1208
1208
1209
1210
    /**
1211
     * Close the server socket (to prevent further connections) if
1212
     * {@link #getBindOnInit()} is {@code false}.
1213
     */
1214
    public final void closeServerSocket() {
1215
        if (!getBindOnInit()) {
1216
            try {
1217
                doCloseServerSocket();
1218
            } catch (IOException ioe) {
1219
                getLog().warn(sm.getString("endpoint.serverSocket.closeFailed", getName()), ioe);
1220
            }
1221
        }
1222
    }
1223
1224
1225
    /**
1226
     * Actually close the server socket but don't perform any other clean-up.
1227
     *
1228
     * @throws IOException If an error occurs closing the socket
1229
     */
1230
    protected abstract void doCloseServerSocket() throws IOException;
1231
1209
    protected abstract U serverSocketAccept() throws Exception;
1232
    protected abstract U serverSocketAccept() throws Exception;
1210
1233
1211
    protected abstract boolean setSocketOptions(U socket);
1234
    protected abstract boolean setSocketOptions(U socket);
(-)java/org/apache/tomcat/util/net/AprEndpoint.java (-6 / +12 lines)
Lines 92-98 Link Here
92
    /**
92
    /**
93
     * Server socket "pointer".
93
     * Server socket "pointer".
94
     */
94
     */
95
    protected long serverSock = 0;
95
    protected volatile long serverSock = 0;
96
96
97
97
98
    /**
98
    /**
Lines 774-784 Link Here
774
            serverSockPool = 0;
774
            serverSockPool = 0;
775
        }
775
        }
776
776
777
        // Close server socket if it was initialised
777
        doCloseServerSocket();
778
        if (serverSock != 0) {
779
            Socket.close(serverSock);
780
            serverSock = 0;
781
        }
782
778
783
        if (sslContext != 0) {
779
        if (sslContext != 0) {
784
            Long ctx = Long.valueOf(sslContext);
780
            Long ctx = Long.valueOf(sslContext);
Lines 799-804 Link Here
799
    }
795
    }
800
796
801
797
798
    @Override
799
    protected void doCloseServerSocket() {
800
        // Close server socket if it was initialised
801
        if (serverSock != 0) {
802
            Socket.close(serverSock);
803
            serverSock = 0;
804
        }
805
    }
806
807
802
    // ------------------------------------------------------ Protected Methods
808
    // ------------------------------------------------------ Protected Methods
803
809
804
    /**
810
    /**
(-)java/org/apache/tomcat/util/net/LocalStrings.properties (+1 lines)
Lines 67-72 Link Here
67
endpoint.sendfile.addfail=Sendfile failure: [{0}] [{1}]
67
endpoint.sendfile.addfail=Sendfile failure: [{0}] [{1}]
68
endpoint.sendfile.error=Unexpected sendfile error
68
endpoint.sendfile.error=Unexpected sendfile error
69
endpoint.sendfileThreadStop=The sendfile thread failed to stop in a timely manner
69
endpoint.sendfileThreadStop=The sendfile thread failed to stop in a timely manner
70
endpoint.serverSocket.closeFailed=Failed to close server socket for [{0}]
70
endpoint.setAttribute=Set [{0}] to [{1}]
71
endpoint.setAttribute=Set [{0}] to [{1}]
71
endpoint.timeout.err=Error processing socket timeout
72
endpoint.timeout.err=Error processing socket timeout
72
endpoint.unknownSslHostName=The SSL host name [{0}] is not recognised for this endpoint
73
endpoint.unknownSslHostName=The SSL host name [{0}] is not recognised for this endpoint
(-)java/org/apache/tomcat/util/net/Nio2Endpoint.java (-4 / +12 lines)
Lines 70-76 Link Here
70
    /**
70
    /**
71
     * Server socket "pointer".
71
     * Server socket "pointer".
72
     */
72
     */
73
    private AsynchronousServerSocketChannel serverSock = null;
73
    private volatile AsynchronousServerSocketChannel serverSock = null;
74
74
75
    /**
75
    /**
76
     * Allows detecting if a completion handler completes inline.
76
     * Allows detecting if a completion handler completes inline.
Lines 227-235 Link Here
227
        if (running) {
227
        if (running) {
228
            stop();
228
            stop();
229
        }
229
        }
230
        // Close server socket
230
        doCloseServerSocket();
231
        serverSock.close();
232
        serverSock = null;
233
        destroySsl();
231
        destroySsl();
234
        super.unbind();
232
        super.unbind();
235
        // Unlike other connectors, the thread pool is tied to the server socket
233
        // Unlike other connectors, the thread pool is tied to the server socket
Lines 241-246 Link Here
241
239
242
240
243
    @Override
241
    @Override
242
    protected void doCloseServerSocket() throws IOException {
243
        // Close server socket
244
        if (serverSock != null) {
245
            serverSock.close();
246
            serverSock = null;
247
        }
248
    }
249
250
251
    @Override
244
    public void shutdownExecutor() {
252
    public void shutdownExecutor() {
245
        if (threadGroup != null && internalExecutor) {
253
        if (threadGroup != null && internalExecutor) {
246
            try {
254
            try {
(-)java/org/apache/tomcat/util/net/NioEndpoint.java (-7 / +13 lines)
Lines 85-91 Link Here
85
    /**
85
    /**
86
     * Server socket "pointer".
86
     * Server socket "pointer".
87
     */
87
     */
88
    private ServerSocketChannel serverSock = null;
88
    private volatile ServerSocketChannel serverSock = null;
89
89
90
    /**
90
    /**
91
     *
91
     *
Lines 328-339 Link Here
328
        if (running) {
328
        if (running) {
329
            stop();
329
            stop();
330
        }
330
        }
331
        if (!getUseInheritedChannel()) {
331
        doCloseServerSocket();
332
            // Close server socket
333
            serverSock.socket().close();
334
            serverSock.close();
335
        }
336
        serverSock = null;
337
        destroySsl();
332
        destroySsl();
338
        super.unbind();
333
        super.unbind();
339
        if (getHandler() != null ) {
334
        if (getHandler() != null ) {
Lines 346-351 Link Here
346
    }
341
    }
347
342
348
343
344
    @Override
345
    protected void doCloseServerSocket() throws IOException {
346
        if (!getUseInheritedChannel() && serverSock != null) {
347
            // Close server socket
348
            serverSock.socket().close();
349
            serverSock.close();
350
            serverSock = null;
351
        }
352
    }
353
354
349
    // ------------------------------------------------------ Protected Methods
355
    // ------------------------------------------------------ Protected Methods
350
356
351
    public NioSelectorPool getSelectorPool() {
357
    public NioSelectorPool getSelectorPool() {

Return to bug 62515