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 TCP connection issues #793

Closed
wants to merge 1 commit into from
Closed

Fix TCP connection issues #793

wants to merge 1 commit into from

Conversation

kean
Copy link
Contributor

@kean kean commented Apr 18, 2024

Description

Related PR wordpress-mobile/WordPress-iOS#23035

ℹ Please replace the above with a link to the issue this pull request addresses, as well as a summary of the implementation details.

Testing Details

ℹ Please replace this with a clear and concise description of the steps required to validate this pull request.


  • Please check here if your pull request includes additional test coverage.
  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

var additionalHeaders: [String: AnyObject] = [:]
if let oAuthToken = self.oAuthToken {
if let oAuthToken {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if this is required for background sessions? Probably not.

}()

private func sessionConfiguration(background: Bool) -> URLSessionConfiguration {
let configuration = background ? URLSessionConfiguration.background(withIdentifier: self.backgroundSessionIdentifier) : URLSessionConfiguration.default
private static var urlSession = URLSession(configuration: .default)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBD: apply the same treatment to .org and XMLRPC.

for session in [urlSession, uploadURLSession] {
session.finishTasksAndInvalidate()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One side effect is ongoing tasks won't be invalidated at all. I wonder if we should make WordPressComRestApi accept a URLSession instance, which the app can create upon use signing in and invalidate upon logout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a need to invalidate it? The requests are signed on a per-request basis now.

Something does need to change with the WordPressComRestApi/invalidateAndCancelTasks usage. The lifetime of _wordPressComRestApi is tied to a WPAccount, which is also problematic: there is one instance per thread, and the instances could get reset.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need to invalidate it?

Good question. I don't know for sure though. Using a shared URLSession singleton between user sessions is a change introduced in this PR, which we'll need to test to make sure it doesn't break things.

IMO, the best practice is URLSession instance should be per user session. Upon user logs in, they get a new URLSession instance and uses it until logs out. Once logs out, the URLSession instance should be destroyed. That's similar to how Safari uses one URLSession for each tab.

The lifetime of _wordPressComRestApi is tied to a WPAccount, which is also problematic: there is one instance per thread, and the instances could get reset.

Yes, definitely. That's another big piece of tech debt.

Copy link
Contributor Author

@kean kean Apr 19, 2024

Choose a reason for hiding this comment

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

IMO, the best practice is URLSession instance should be per user session. Upon user logs in, they get a new URLSession instance and uses it until logs out. Once logs out, the URLSession instance should be destroyed. That's similar to how Safari uses one URLSession for each tab.

I completely agree. The app should have a repository that could control the lifetime of the objects to match the lifetime of the user session. It will be a better fix for this issue as well (assuming it actually fixes it because I don't have any hard evidence yet).

@kean kean closed this May 7, 2024
@kean kean deleted the fix/tcp-connection-issue branch May 7, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants