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

(-)java/org/apache/catalina/core/LocalStrings.properties (+1 lines)
Lines 203-208 Link Here
203
standardService.engine.stopFailed=Failed to stop associated Engine
203
standardService.engine.stopFailed=Failed to stop associated Engine
204
standardService.mapperListener.startFailed=Failed to start associated MapperListener
204
standardService.mapperListener.startFailed=Failed to start associated MapperListener
205
standardService.mapperListener.stopFailed=Failed to stop associated MapperListener
205
standardService.mapperListener.stopFailed=Failed to stop associated MapperListener
206
standardService.serverSocket.closeFailed=Failed to close server socket for [{0}]
206
standardService.start.name=Starting service [{0}]
207
standardService.start.name=Starting service [{0}]
207
standardService.stop.name=Stopping service [{0}]
208
standardService.stop.name=Stopping service [{0}]
208
standardWrapper.allocate=Error allocating a servlet instance
209
standardWrapper.allocate=Error allocating a servlet instance
(-)java/org/apache/catalina/core/StandardService.java (+10 lines)
Lines 19-24 Link Here
19
19
20
import java.beans.PropertyChangeListener;
20
import java.beans.PropertyChangeListener;
21
import java.beans.PropertyChangeSupport;
21
import java.beans.PropertyChangeSupport;
22
import java.io.IOException;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
23
24
24
import javax.management.ObjectName;
25
import javax.management.ObjectName;
Lines 458-463 Link Here
458
        synchronized (connectorsLock) {
459
        synchronized (connectorsLock) {
459
            for (Connector connector: connectors) {
460
            for (Connector connector: connectors) {
460
                connector.pause();
461
                connector.pause();
462
                if (!Boolean.parseBoolean((String) connector.getProperty("bindOnInit"))) {
463
                    // Close server socket
464
                    try {
465
                        connector.getProtocolHandler().closeServerSocket();
466
                    } catch (IOException e) {
467
                        log.warn(sm.getString(
468
                                "standardService.serverSocket.closeFailed", connector), e);
469
                    }
470
                }
461
            }
471
            }
462
        }
472
        }
463
473
(-)java/org/apache/coyote/AbstractProtocol.java (+7 lines)
Lines 16-21 Link Here
16
 */
16
 */
17
package org.apache.coyote;
17
package org.apache.coyote;
18
18
19
import java.io.IOException;
19
import java.net.InetAddress;
20
import java.net.InetAddress;
20
import java.nio.ByteBuffer;
21
import java.nio.ByteBuffer;
21
import java.util.Collections;
22
import java.util.Collections;
Lines 631-636 Link Here
631
    }
632
    }
632
633
633
634
635
    @Override
636
    public void closeServerSocket() throws IOException {
637
        endpoint.closeServerSocket();
638
    }
639
640
634
    // ------------------------------------------- Connection handler base class
641
    // ------------------------------------------- Connection handler base class
635
642
636
    protected static class ConnectionHandler<S> implements AbstractEndpoint.Handler<S> {
643
    protected static class ConnectionHandler<S> implements AbstractEndpoint.Handler<S> {
(-)java/org/apache/coyote/ProtocolHandler.java (+10 lines)
Lines 16-21 Link Here
16
 */
16
 */
17
package org.apache.coyote;
17
package org.apache.coyote;
18
18
19
import java.io.IOException;
19
import java.util.concurrent.Executor;
20
import java.util.concurrent.Executor;
20
21
21
import org.apache.tomcat.util.net.SSLHostConfig;
22
import org.apache.tomcat.util.net.SSLHostConfig;
Lines 101-106 Link Here
101
102
102
103
103
    /**
104
    /**
105
     * Close the server socket (to prevent further connections) but do not
106
     * perform any further shutdown.
107
     *
108
     * @throws IOException If an error occurs closing the server socket
109
     */
110
    public void closeServerSocket() throws IOException;
111
112
113
    /**
104
     * Requires APR/native library
114
     * Requires APR/native library
105
     *
115
     *
106
     * @return <code>true</code> if this Protocol Handler requires the
116
     * @return <code>true</code> if this Protocol Handler requires the
(-)java/org/apache/tomcat/util/net/AbstractEndpoint.java (-6 / +15 lines)
Lines 64-69 Link Here
64
64
65
    protected static final StringManager sm = StringManager.getManager(AbstractEndpoint.class);
65
    protected static final StringManager sm = StringManager.getManager(AbstractEndpoint.class);
66
66
67
    private static final String SOCKET_PROPERTY_PREFIX = "socket.";
68
67
    public static interface Handler<S> {
69
    public static interface Handler<S> {
68
70
69
        /**
71
        /**
Lines 741-750 Link Here
741
743
742
    public boolean setProperty(String name, String value) {
744
    public boolean setProperty(String name, String value) {
743
        setAttribute(name, value);
745
        setAttribute(name, value);
744
        final String socketName = "socket.";
745
        try {
746
        try {
746
            if (name.startsWith(socketName)) {
747
            if (name.startsWith(SOCKET_PROPERTY_PREFIX)) {
747
                return IntrospectionUtils.setProperty(socketProperties, name.substring(socketName.length()), value);
748
                return IntrospectionUtils.setProperty(
749
                        socketProperties, name.substring(SOCKET_PROPERTY_PREFIX.length()), value);
748
            } else {
750
            } else {
749
                return IntrospectionUtils.setProperty(this,name,value,false);
751
                return IntrospectionUtils.setProperty(this,name,value,false);
750
            }
752
            }
Lines 755-763 Link Here
755
    }
757
    }
756
    public String getProperty(String name) {
758
    public String getProperty(String name) {
757
        String value = (String) getAttribute(name);
759
        String value = (String) getAttribute(name);
758
        final String socketName = "socket.";
760
        if (value == null) {
759
        if (value == null && name.startsWith(socketName)) {
761
            Object result;
760
            Object result = IntrospectionUtils.getProperty(socketProperties, name.substring(socketName.length()));
762
            if (name.startsWith(SOCKET_PROPERTY_PREFIX)) {
763
                result = IntrospectionUtils.getProperty(
764
                        socketProperties, name.substring(SOCKET_PROPERTY_PREFIX.length()));
765
            } else {
766
                result = IntrospectionUtils.getProperty(this, name);
767
            }
761
            if (result != null) {
768
            if (result != null) {
762
                value = result.toString();
769
                value = result.toString();
763
            }
770
            }
Lines 1208-1213 Link Here
1208
1215
1209
    protected abstract U serverSocketAccept() throws Exception;
1216
    protected abstract U serverSocketAccept() throws Exception;
1210
1217
1218
    public abstract void closeServerSocket() throws IOException;
1219
1211
    protected abstract boolean setSocketOptions(U socket);
1220
    protected abstract boolean setSocketOptions(U socket);
1212
1221
1213
    protected abstract void closeSocket(U socket);
1222
    protected abstract void closeSocket(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
        closeServerSocket();
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
    public void closeServerSocket() {
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/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
        closeServerSocket();
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
    public void closeServerSocket() 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
        closeServerSocket();
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
    public void closeServerSocket() 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