From 947429beb4b3f7515bfe2f1d7bb721318cf30935 Mon Sep 17 00:00:00 2001 From: Ilya Teterin Date: Fri, 27 Nov 2020 17:57:25 +0000 Subject: [PATCH] Address warning reported by thread safety analyzer (#319) 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