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

Fix crash when download large file #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion Sources/Packages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public final class TrafficPackage: Codable, CustomDebugStringConvertible, Serial
// Construct the Response without body
self.response = Response(response)
}

func updateDidComplete(_ error: Error?) {
endAt = Date().timeIntervalSince1970
if let error = error {
Expand All @@ -170,6 +170,12 @@ public final class TrafficPackage: Codable, CustomDebugStringConvertible, Serial
return
}
lastData = data

// Avoid memory consumes in app when download large file that causing crash app
guard responseBodyData.count < NetServiceTransport.MaximumSizeResponse else {
endAt = Date().timeIntervalSince1970
return
}
responseBodyData.append(data)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Transporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class NetServiceTransport: NSObject {
// For some reason, Stream Task could send a big file
// https://github.com/ProxymanApp/atlantis/issues/57
static let MaximumSizePackage = 52428800 // 50Mb

static let MaximumSizeResponse = 2097152 // 2MB
Copy link
Member

@NghiaTranUIT NghiaTranUIT Apr 10, 2022

Choose a reason for hiding this comment

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

I suppose that we should increase the MaximumSizeResponse to 5Mb or 10Mb. 2Mb is likely too small.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, It likely too small, I'm fixing to 10 MB and you can check it.
Thank you

private let serviceBrowser: NetServiceBrowser
private var services: [NetService] = []
private let queue = DispatchQueue(label: "com.proxyman.atlantis.netservices") // Serial on purpose
Expand Down