Skip to content

Commit 1f87e8c

Browse files
authored
Nil out the onStart callback after using it (#1570)
Motivation: The `ClientTransport` has an `onStart` callback which is called once the stream has been established. For async calls this is used to notify the writability manager that it may now start writing. The callback references the call which holds the transport which holds the callback forming a strong retain cycle and a slow memory leak. The transport should break this cycle. Modifications: - nil out the `onStart` callback after it has been called. Result: Fixes a leak
1 parent c4682a9 commit 1f87e8c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: Sources/GRPC/Interceptor/ClientTransport.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal final class ClientTransport<Request, Response> {
9494
private var channel: Channel?
9595

9696
/// A callback which is invoked once when the stream channel becomes active.
97-
private let onStart: () -> Void
97+
private var onStart: (() -> Void)?
9898

9999
/// Our current state as logging metadata.
100100
private var stateForLogging: Logger.MetadataValue {
@@ -945,7 +945,8 @@ extension ClientTransport {
945945
// Messages are buffered by this class and in the async writer for async calls. Initially the
946946
// async writer is not allowed to emit messages; the call to 'onStart()' signals that messages
947947
// may be emitted. We call it here to avoid races between writing headers and messages.
948-
self.onStart()
948+
self.onStart?()
949+
self.onStart = nil
949950

950951
case let .message(request, metadata):
951952
do {

0 commit comments

Comments
 (0)