Skip to content

Commit 5f71d60

Browse files
Fix lock issues around disableSSL and IOBuffer (#2295)
* Renamed locks in IOBuffer, disableSSL should have had its own lock * Renamed locks in IOBuffer, disableSSL should have had its own lock * TDSChannelLock --> tdsChannelLock * Renamed TDSReader lock --> tdsReaderLock * TDSChannelLock --> tdsChannelLock * Renamed TDSReader lock --> tdsReaderLock
1 parent 066aeeb commit 5f71d60

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ final boolean isLoggingPackets() {
672672
int numMsgsSent = 0;
673673
int numMsgsRcvd = 0;
674674

675-
private final transient Lock lock = new ReentrantLock();
675+
private final transient Lock tdsChannelLock = new ReentrantLock();
676676

677677
// Last SPID received from the server. Used for logging and to tag subsequent outgoing
678678
// packets to facilitate diagnosing problems from the server side.
@@ -773,7 +773,7 @@ void disableSSL() {
773773
logger.finer(toString() + " Disabling SSL...");
774774
}
775775

776-
lock.lock();
776+
tdsChannelLock.lock();
777777
try {
778778
// Guard in case of disableSSL being called before enableSSL
779779
if (proxySocket == null) {
@@ -839,7 +839,7 @@ void disableSSL() {
839839
channelSocket = tcpSocket;
840840
sslSocket = null;
841841
} finally {
842-
lock.unlock();
842+
tdsChannelLock.unlock();
843843
}
844844

845845
if (logger.isLoggable(Level.FINER))
@@ -1056,6 +1056,8 @@ private void writeInternal(byte[] b, int off, int len) throws IOException {
10561056
private final class ProxyInputStream extends InputStream {
10571057
private InputStream filteredStream;
10581058

1059+
private final transient Lock proxyInputStreamLock = new ReentrantLock();
1060+
10591061
/**
10601062
* Bytes that have been read by a poll(s).
10611063
*/
@@ -1082,7 +1084,7 @@ final void setFilteredStream(InputStream is) {
10821084
* If an I/O exception occurs.
10831085
*/
10841086
public boolean poll() {
1085-
lock.lock();
1087+
proxyInputStreamLock.lock();
10861088
try {
10871089
int b;
10881090
try {
@@ -1117,7 +1119,7 @@ public boolean poll() {
11171119

11181120
return true;
11191121
} finally {
1120-
lock.unlock();
1122+
proxyInputStreamLock.unlock();
11211123
}
11221124
}
11231125

@@ -1133,7 +1135,7 @@ private int getOneFromCache() {
11331135

11341136
@Override
11351137
public long skip(long n) throws IOException {
1136-
lock.lock();
1138+
proxyInputStreamLock.lock();
11371139
try {
11381140
long bytesSkipped = 0;
11391141

@@ -1154,7 +1156,7 @@ public long skip(long n) throws IOException {
11541156

11551157
return bytesSkipped;
11561158
} finally {
1157-
lock.unlock();
1159+
proxyInputStreamLock.unlock();
11581160
}
11591161
}
11601162

@@ -1191,7 +1193,7 @@ public int read(byte[] b, int offset, int maxBytes) throws IOException {
11911193
}
11921194

11931195
private int readInternal(byte[] b, int offset, int maxBytes) throws IOException {
1194-
lock.lock();
1196+
proxyInputStreamLock.lock();
11951197
try {
11961198
int bytesRead;
11971199

@@ -1240,7 +1242,7 @@ private int readInternal(byte[] b, int offset, int maxBytes) throws IOException
12401242

12411243
return bytesRead;
12421244
} finally {
1243-
lock.unlock();
1245+
proxyInputStreamLock.unlock();
12441246
}
12451247
}
12461248

@@ -1259,11 +1261,11 @@ public void mark(int readLimit) {
12591261
if (logger.isLoggable(Level.FINEST))
12601262
logger.finest(super.toString() + " Marking next " + readLimit + " bytes");
12611263

1262-
lock.lock();
1264+
proxyInputStreamLock.lock();
12631265
try {
12641266
filteredStream.mark(readLimit);
12651267
} finally {
1266-
lock.unlock();
1268+
proxyInputStreamLock.unlock();
12671269
}
12681270
}
12691271

@@ -1272,12 +1274,12 @@ public void reset() throws IOException {
12721274
if (logger.isLoggable(Level.FINEST))
12731275
logger.finest(super.toString() + " Resetting to previous mark");
12741276

1275-
lock.lock();
1277+
proxyInputStreamLock.lock();
12761278
try {
12771279

12781280
filteredStream.reset();
12791281
} finally {
1280-
lock.unlock();
1282+
proxyInputStreamLock.unlock();
12811283
}
12821284
}
12831285

@@ -6688,7 +6690,7 @@ final SQLServerConnection getConnection() {
66886690
private boolean serverSupportsColumnEncryption = false;
66896691
private boolean serverSupportsDataClassification = false;
66906692
private byte serverSupportedDataClassificationVersion = TDS.DATA_CLASSIFICATION_NOT_ENABLED;
6691-
private final transient Lock lock = new ReentrantLock();
6693+
private final transient Lock tdsReaderLock = new ReentrantLock();
66926694

66936695
private final byte[] valueBytes = new byte[256];
66946696

@@ -6808,7 +6810,7 @@ private boolean nextPacket() throws SQLServerException {
68086810
* the response and another thread that is trying to buffer it with TDSCommand.detach().
68096811
*/
68106812
final boolean readPacket() throws SQLServerException {
6811-
lock.lock();
6813+
tdsReaderLock.lock();
68126814
try {
68136815
if (null != command && !command.readingResponse())
68146816
return false;
@@ -6921,7 +6923,7 @@ final boolean readPacket() throws SQLServerException {
69216923

69226924
return true;
69236925
} finally {
6924-
lock.unlock();
6926+
tdsReaderLock.unlock();
69256927
}
69266928
}
69276929

0 commit comments

Comments
 (0)