Skip to content

Commit 4e97f21

Browse files
committed
Ensure encryption timeouts are enough for testing against
Also prevent NPE leak from TlsChannelImpl Also added temp fix for timeoutRemainingMS (scheduled to be removed) JAVA-5401 Added temp fix for timeoutRemainingMS which will eventually be removed
1 parent b169c3a commit 4e97f21

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

driver-core/src/main/com/mongodb/internal/TimeoutContext.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,16 @@ public TimeoutContext withAdditionalReadTimeout(final int additionalReadTimeout)
269269

270270
private long timeoutRemainingMS() {
271271
assertNotNull(timeout);
272-
if (timeout.hasExpired()) {
273-
throw createMongoTimeoutException("The operation timeout has expired.");
272+
273+
if (timeout.isInfinite()) {
274+
return 0;
275+
}
276+
long remaining = timeout.remaining(MILLISECONDS);
277+
if (remaining > 0) {
278+
return remaining;
274279
}
275-
return timeout.isInfinite() ? 0 : timeout.remaining(MILLISECONDS);
280+
281+
throw createMongoTimeoutException("The operation timeout has expired.");
276282
}
277283

278284
@Override

driver-core/src/main/com/mongodb/internal/connection/tlschannel/impl/TlsChannelImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ private int handshake(Optional<ByteBufferSet> dest, Optional<HandshakeStatus> ha
554554
try {
555555
writeLock.lock();
556556
try {
557+
if (invalid || shutdownSent) {
558+
throw new ClosedChannelException();
559+
}
557560
Util.assertTrue(inPlain.nullOrEmpty());
558561
outEncrypted.prepare();
559562
try {

driver-core/src/test/resources/client-side-encryption/legacy/timeoutMS.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"minServerVersion": "4.4"
55
}
66
],
7+
"comment": "Updated timeoutMS and blockTimeMS manually to address race conditions in tests with SSL handshake.",
78
"database_name": "cse-timeouts-db",
89
"collection_name": "cse-timeouts-coll",
910
"data": [],
@@ -100,7 +101,6 @@
100101
"tests": [
101102
{
102103
"description": "timeoutMS applied to listCollections to get collection schema",
103-
"comment": "Updated timeoutMS and blockTimeMS manually to address race conditions in tests with SSL handshake.",
104104
"failPoint": {
105105
"configureFailPoint": "failCommand",
106106
"mode": {
@@ -111,7 +111,7 @@
111111
"listCollections"
112112
],
113113
"blockConnection": true,
114-
"blockTimeMS": 100
114+
"blockTimeMS": 250
115115
}
116116
},
117117
"clientOptions": {
@@ -120,7 +120,7 @@
120120
"aws": {}
121121
}
122122
},
123-
"timeoutMS": 90
123+
"timeoutMS": 200
124124
},
125125
"operations": [
126126
{
@@ -170,7 +170,7 @@
170170
"find"
171171
],
172172
"blockConnection": true,
173-
"blockTimeMS": 20
173+
"blockTimeMS": 200
174174
}
175175
},
176176
"clientOptions": {
@@ -179,7 +179,7 @@
179179
"aws": {}
180180
}
181181
},
182-
"timeoutMS": 50
182+
"timeoutMS": 500
183183
},
184184
"operations": [
185185
{

driver-sync/src/test/functional/com/mongodb/client/AbstractClientSideEncryptionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ public void shouldPassAllOutcomes() {
318318
BsonValue expectedResult = operation.get("result");
319319
try {
320320
BsonDocument actualOutcome = helper.getOperationResults(operation);
321+
assertFalse(String.format("Expected a timeout error but got: %s", actualOutcome.toJson()), hasTimeoutError(expectedResult));
322+
321323
if (expectedResult != null) {
322324
BsonValue actualResult = actualOutcome.get("result", new BsonString("No result or error"));
323325
assertBsonValue("Expected operation result differs from actual", expectedResult, actualResult);

0 commit comments

Comments
 (0)