Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Sources/GRPC/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ internal class ConnectionManager {
switch self.state {
case .idle:
self.monitor.updateState(to: .idle, logger: self.logger)

// Create a new id; it'll be used for the *next* channel we create.
self.channelNumberLock.withLockVoid {
self.channelNumber &+= 1
}
self.logger[metadataKey: MetadataKey.connectionID] = "\(self.connectionIDAndNumber)"
self.updateConnectionID()

case .connecting:
self.monitor.updateState(to: .connecting, logger: self.logger)
Expand All @@ -183,6 +178,7 @@ internal class ConnectionManager {

case .transientFailure:
self.monitor.updateState(to: .transientFailure, logger: self.logger)
self.updateConnectionID()

case .shutdown:
self.monitor.updateState(to: .shutdown, logger: self.logger)
Expand All @@ -198,9 +194,20 @@ internal class ConnectionManager {
private var channelNumber: UInt64
private var channelNumberLock = Lock()

private var _connectionIDAndNumber: String {
return "\(self.connectionID)/\(self.channelNumber)"
}

private var connectionIDAndNumber: String {
return self.channelNumberLock.withLock {
return "\(self.connectionID)/\(self.channelNumber)"
return self._connectionIDAndNumber
}
}

private func updateConnectionID() {
self.channelNumberLock.withLockVoid {
self.channelNumber &+= 1
self.logger[metadataKey: MetadataKey.connectionID] = "\(self._connectionIDAndNumber)"
}
}

Expand Down