Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

fix URLsession leak in ServiceTokenProvider#80

Open
pbk20191 wants to merge 1 commit into
googleapis:mainfrom
pbk20191:featulre/fix-urlsession_leak
Open

fix URLsession leak in ServiceTokenProvider#80
pbk20191 wants to merge 1 commit into
googleapis:mainfrom
pbk20191:featulre/fix-urlsession_leak

Conversation

@pbk20191

@pbk20191 pbk20191 commented May 8, 2025

Copy link
Copy Markdown

URLsession does not dispose automatically when reference count is 0.
This is documented behavior.

class Foo: NSObject, URLSessionDelegate {
    
    func urlSession(_ session: URLSession, didBecomeInvalidWithError error: (any Error)?) {
        print("invalid session")
    }
    
    deinit {
        print("deinit")
    }
}
// nothing printed!!
do {
    let a : URLSession = URLSession(configuration: .default, delegate: Sooo(), delegateQueue: nil)
    let _ = a
}

So, creating URLSession every time to create Token cause URLSession to be leaked,
I would suggest to use default shared Session instead.

@pbk20191
pbk20191 requested a review from a team May 8, 2025 23:18
@google-cla

google-cla Bot commented May 8, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pbk20191
pbk20191 force-pushed the featulre/fix-urlsession_leak branch from 00c8abb to fee4934 Compare May 9, 2025 00:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant