Skip to content

Commit

Permalink
Address warning reported by thread safety analyzer (#319)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ya-pulser committed Nov 27, 2020
1 parent 0a8dddb commit 947429b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/AsyncHTTPClient/ConnectionPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 947429b

Please sign in to comment.