Skip to content

Commit 74a86f1

Browse files
authored
SWIFT-1214 Error on maxPoolSize=0 in connection string as well as options struct (#670)
1 parent 29df829 commit 74a86f1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/MongoSwift/ConnectionString.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ internal class ConnectionString {
300300
}
301301

302302
try self.setInt32Option(MONGOC_URI_MAXPOOLSIZE, to: value)
303+
// libmongoc treats a maxPoolSize of 0 as 1, which is not spec-compliant (it should be treated as "no max"),
304+
// so we error if a user tries to set that via the connection string. See SWIFT-1339
305+
} else if let uriMaxPoolSize = self.options?[MONGOC_URI_MAXPOOLSIZE]?.int32Value {
306+
guard uriMaxPoolSize > 0 else {
307+
throw self.int32OutOfRangeError(
308+
option: MONGOC_URI_MAXPOOLSIZE,
309+
value: uriMaxPoolSize,
310+
min: 1,
311+
max: Int32.max
312+
)
313+
}
303314
}
304315

305316
if let connectTimeoutMS = options?.connectTimeoutMS {

Tests/MongoSwiftTests/ConnectionStringTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ let skipUnsupported: [String: [String]] = [
115115
"Non-numeric maxIdleTimeMS causes a warning",
116116
"Valid connection pool options are parsed correctly",
117117
// We don't support minPoolSize.
118-
"minPoolSize=0 does not error"
118+
"minPoolSize=0 does not error",
119+
// We don't allow maxPoolSize=0, see SWIFT-1339.
120+
"maxPoolSize=0 does not error"
119121
],
120122
// requires maxIdleTimeMS
121123
"connection-options.json": [

0 commit comments

Comments
 (0)