Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketLeak.java
41152 views
/*1* Copyright (c) 2020 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;2425import javax.net.SocketFactory;26import javax.net.ssl.SSLSocketFactory;2728import jdk.test.lib.Platform;29import jdk.test.lib.util.FileUtils;3031/*32* @test33* @bug 8256818 8257670 8257884 825799734* @summary Test that creating and closing SSL Sockets without bind/connect35* will not leave leaking socket file descriptors36* @library /test/lib37* @run main/othervm SSLSocketLeak38*/39public class SSLSocketLeak {4041// number of sockets to open/close42private static final int NUM_TEST_SOCK = 500;4344// percentage of accepted growth of open handles45private static final int OPEN_HANDLE_GROWTH_THRESHOLD_PERCENTAGE = Platform.isWindows() ? 25 : 10;4647public static void main(String[] args) throws IOException {48long fds_start = FileUtils.getProcessHandleCount();49System.out.println("FDs at the beginning: " + fds_start);5051SocketFactory f = SSLSocketFactory.getDefault();52for (int i = 0; i < NUM_TEST_SOCK; i++) {53f.createSocket().close();54}5556long fds_end = FileUtils.getProcessHandleCount();57System.out.println("FDs in the end: " + fds_end);5859if ((fds_end - fds_start) > ((NUM_TEST_SOCK * OPEN_HANDLE_GROWTH_THRESHOLD_PERCENTAGE)) / 100) {60throw new RuntimeException("Too many open file descriptors. Looks leaky.");61}62}63}646566