Skip to content

Commit

Permalink
Fetcher: re-use URLSession (#976)
Browse files Browse the repository at this point in the history
Otherwise we start to periodically get RST's from GitHub, possibly
because of too many connection opens, which has an effect of cancelling
previously received bytes.

These RST's can be observed in tcpdump/Wireshark or Console, emitted
from the libusrtcp.dylib library, com.apple.network subsystem, for the
Tart process:

>tcp_input [C59.1.1.1:3] flags=[R] seq=1805021659, ack=0, win=0 state=CLOSED rcv_nxt=1805021659, snd_una=1752355607

You can also observe the "Received Bytes" in "Activity Monitor" for
the Tart process while pulling ghcr.io/cirruslabs/macos-runner:sequoia,
and this value will periodically decrease.
  • Loading branch information
edigaryev authored Dec 17, 2024
1 parent e27da23 commit eaec015
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Sources/tart/Fetcher.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

fileprivate var urlSessionConfiguration: URLSessionConfiguration {
fileprivate var urlSession: URLSession = {
let config = URLSessionConfiguration.default

// Harbor expects a CSRF token to be present if the HTTP client
Expand All @@ -13,14 +13,15 @@ fileprivate var urlSessionConfiguration: URLSessionConfiguration {
// [2]: https://github.com/cirruslabs/tart/issues/295
config.httpShouldSetCookies = false

return config
}
return URLSession(configuration: config)
}()

class Fetcher {
static func fetch(_ request: URLRequest, viaFile: Bool = false, progress: Progress? = nil) async throws -> (AsyncThrowingStream<Data, Error>, HTTPURLResponse) {
let task = urlSession.dataTask(with: request)

let delegate = Delegate()
let session = URLSession(configuration: urlSessionConfiguration, delegate: delegate, delegateQueue: nil)
let task = session.dataTask(with: request)
task.delegate = delegate

let stream = AsyncThrowingStream<Data, Error> { continuation in
delegate.streamContinuation = continuation
Expand Down

0 comments on commit eaec015

Please sign in to comment.