Skip to content

Commit d3956a6

Browse files
authored
Merge pull request ibmruntimes#386 from shruacha1234/PreClose_hang
Avoid hang in preClose method during dup2 system call
2 parents 94ec587 + 605ea21 commit d3956a6

File tree

7 files changed

+99
-6
lines changed

7 files changed

+99
-6
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* ===========================================================================
3+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
4+
* ===========================================================================
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* IBM designates this particular file as subject to the "Classpath" exception
11+
* as provided by IBM in the LICENSE file that accompanied this code.
12+
*
13+
* This code is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
* version 2 for more details (a copy is included in the LICENSE file that
17+
* accompanied this code).
18+
*
19+
* You should have received a copy of the GNU General Public License version
20+
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* ===========================================================================
23+
*/
24+
package sun.net.util;
25+
26+
import sun.security.action.GetPropertyAction;
27+
28+
public final class AIX {
29+
// Flag indicating whether the operating system is AIX.
30+
public static final boolean isAIX = "AIX".equals(GetPropertyAction.privilegedGetProperty("os.name"));
31+
}

src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -72,6 +78,7 @@
7278
import jdk.internal.ref.CleanerFactory;
7379
import sun.net.ResourceManager;
7480
import sun.net.ext.ExtendedSocketOptions;
81+
import sun.net.util.AIX;
7582
import sun.net.util.IPAddressUtil;
7683

7784
/**
@@ -1732,11 +1739,14 @@ private void implCloseBlockingMode() throws IOException {
17321739
long reader = readerThread;
17331740
long writer = writerThread;
17341741
if (reader != 0 || writer != 0) {
1735-
nd.preClose(fd);
1742+
if (!AIX.isAIX)
1743+
nd.preClose(fd);
17361744
if (reader != 0)
17371745
NativeThread.signal(reader);
17381746
if (writer != 0)
17391747
NativeThread.signal(writer);
1748+
if (AIX.isAIX)
1749+
nd.preClose(fd);
17401750
}
17411751
}
17421752
}

src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -56,6 +62,7 @@
5662
import sun.net.PlatformSocketImpl;
5763
import sun.net.ResourceManager;
5864
import sun.net.ext.ExtendedSocketOptions;
65+
import sun.net.util.AIX;
5966
import sun.net.util.SocketExceptions;
6067

6168
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -909,13 +916,16 @@ protected void close() throws IOException {
909916
// then the socket is pre-closed and the thread(s) signalled. The
910917
// last thread will close the file descriptor.
911918
if (!tryClose()) {
912-
nd.preClose(fd);
919+
if (!AIX.isAIX)
920+
nd.preClose(fd);
913921
long reader = readerThread;
914922
if (reader != 0)
915923
NativeThread.signal(reader);
916924
long writer = writerThread;
917925
if (writer != 0)
918926
NativeThread.signal(writer);
927+
if (AIX.isAIX)
928+
nd.preClose(fd);
919929
}
920930
}
921931
}

src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -57,6 +63,7 @@
5763

5864
import sun.net.NetHooks;
5965
import sun.net.ext.ExtendedSocketOptions;
66+
import sun.net.util.AIX;
6067

6168
/**
6269
* An implementation of ServerSocketChannels
@@ -583,8 +590,11 @@ private void implCloseBlockingMode() throws IOException {
583590
if (!tryClose()) {
584591
long th = thread;
585592
if (th != 0) {
586-
nd.preClose(fd);
593+
if (!AIX.isAIX)
594+
nd.preClose(fd);
587595
NativeThread.signal(th);
596+
if (AIX.isAIX)
597+
nd.preClose(fd);
588598
}
589599
}
590600
}

src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -62,6 +68,7 @@
6268
import sun.net.ConnectionResetException;
6369
import sun.net.NetHooks;
6470
import sun.net.ext.ExtendedSocketOptions;
71+
import sun.net.util.AIX;
6572
import sun.net.util.SocketExceptions;
6673

6774
/**
@@ -1014,11 +1021,14 @@ private void implCloseBlockingMode() throws IOException {
10141021
long reader = readerThread;
10151022
long writer = writerThread;
10161023
if (reader != 0 || writer != 0) {
1017-
nd.preClose(fd);
1024+
if (!AIX.isAIX)
1025+
nd.preClose(fd);
10181026
if (reader != 0)
10191027
NativeThread.signal(reader);
10201028
if (writer != 0)
10211029
NativeThread.signal(writer);
1030+
if (AIX.isAIX)
1031+
nd.preClose(fd);
10221032
}
10231033
}
10241034
}

src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -37,6 +43,8 @@
3743
import java.util.Objects;
3844
import java.util.concurrent.locks.ReentrantLock;
3945

46+
import sun.net.util.AIX;
47+
4048
class SinkChannelImpl
4149
extends Pipe.SinkChannel
4250
implements SelChImpl
@@ -123,8 +131,11 @@ private void implCloseBlockingMode() throws IOException {
123131
if (!tryClose()) {
124132
long th = thread;
125133
if (th != 0) {
126-
nd.preClose(fd);
134+
if (!AIX.isAIX)
135+
nd.preClose(fd);
127136
NativeThread.signal(th);
137+
if (AIX.isAIX)
138+
nd.preClose(fd);
128139
}
129140
}
130141
}

src/java.base/unix/classes/sun/nio/ch/SourceChannelImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
package sun.nio.ch;
2733

2834
import java.io.FileDescriptor;
@@ -37,6 +43,8 @@
3743
import java.util.Objects;
3844
import java.util.concurrent.locks.ReentrantLock;
3945

46+
import sun.net.util.AIX;
47+
4048
class SourceChannelImpl
4149
extends Pipe.SourceChannel
4250
implements SelChImpl
@@ -123,8 +131,11 @@ private void implCloseBlockingMode() throws IOException {
123131
if (!tryClose()) {
124132
long th = thread;
125133
if (th != 0) {
126-
nd.preClose(fd);
134+
if (!AIX.isAIX)
135+
nd.preClose(fd);
127136
NativeThread.signal(th);
137+
if (AIX.isAIX)
138+
nd.preClose(fd);
128139
}
129140
}
130141
}

0 commit comments

Comments
 (0)