Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPClient needs to be shutdown after use to avoid memory leak #4

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion Examples/PrintPDF/main.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Foundation
import IppClient

let httpClient = HTTPClient(configuration: .init(certificateVerification: .none))

let printer = IppPrinter(
httpClient: HTTPClient(configuration: .init(certificateVerification: .none)),
httpClient: httpClient,
uri: "ipps://macmini.local/printers/EPSON_XP_7100_Series"
)

Expand Down Expand Up @@ -48,3 +50,5 @@ while true {

try await Task.sleep(nanoseconds: 3_000_000_000)
}

try httpClient.syncShutdown()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never executed. The while loop above only exits...

The thing is that is technically completely unnecessary to shutdown the client before terminating anyway (so I did not want to include it in the example) - but having the debug build assertion sure is not nice either...

Also, since we are in an async context, I think this would result in a warning too, right? (we'd have to use .shutdown().get() or something I guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely right, I fixed the spots.

.syncShutdown() doesn't return anything, it throws if an error occurs. So I think we are good with that call.