From 87b87fae86d2d5caedb7c1490ba35b2ca2782880 Mon Sep 17 00:00:00 2001 From: Ilya Teterin Date: Wed, 25 Nov 2020 16:19:06 +0000 Subject: [PATCH] Address warning reported by thread safety analyzer Motivation: Thread safety analyzer reports warning about observable state leaving lock guarded code blocks. This PR address some of the warnings. Analysis of the warning does not prove that we have a real bug and all the warnings are considered as potential bugs. Analyzer used is: `docker run --rm -v $(pwd):/src -w /src swift:5.3.1 swift test -c release --sanitize=thread --enable-test-discovery` Modifications: * accessor to count of connections in connection pool is guarded by lock Result: Most of thread safety warnings are addressed without modification of observable code behaviour. --- Sources/AsyncHTTPClient/ConnectionPool.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/ConnectionPool.swift b/Sources/AsyncHTTPClient/ConnectionPool.swift index 8d8fda20e..1ccd82ee9 100644 --- a/Sources/AsyncHTTPClient/ConnectionPool.swift +++ b/Sources/AsyncHTTPClient/ConnectionPool.swift @@ -110,7 +110,9 @@ final class ConnectionPool { } var count: Int { - return self.providers.count + return self.lock.withLock { + return self.providers.count + } } /// Used by the `ConnectionPool` to index its `HTTP1ConnectionProvider`s