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

NSUrlSessionHandler: Rewind request content to the start before sending #16341

Merged
merged 9 commits into from
Feb 28, 2024

Conversation

wcoder
Copy link
Contributor

@wcoder wcoder commented Oct 13, 2022

Fixes #16339

@mandel-macaque
Copy link
Member

Thanks for this I was looking into this. We need to add a test case before we land this.

@mandel-macaque mandel-macaque added bug If an issue is a bug or a pull request a bug fix do-not-merge Do not merge this pull request labels Oct 14, 2022
@wcoder
Copy link
Contributor Author

wcoder commented Oct 15, 2022

@mandel-macaque

We need to add a test case before we land this.

I agree, can you help me with this:
Is any documentation or guides about tests in this repository? How to setup test environments (add/run tests)?

As I see the right place to add tests is here: ./tests/monotouch-test/System.Net.Http/MessageHandlers.cs. Is It so?

I tried to run ./tests/tests.sln from VS4mac and I can't even compile the solution. Could you help with this?

@mandel-macaque
Copy link
Member

@wcoder I will take care of this and will push a test example to this branch. We can later agree on my tests :)

@mandel-macaque
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wcoder
Copy link
Contributor Author

wcoder commented Oct 24, 2022

@microsoft-github-policy-service agree

Comment on lines 481 to 482
if (stream.CanSeek)
stream.Seek(0, SeekOrigin.Begin);
Copy link
Contributor

@dotMorten dotMorten Oct 24, 2022

Choose a reason for hiding this comment

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

Don't assume that the thing I want to send is from the beginning of the stream. If I do a partial upload of a file (ie resumed upload), I'd have an offset in my filestream. Instead rewind to where the request was originally meant to start from, and definitely only on an automated retry.

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'm not sure that described behavior has been supported before. Do you have an example?

As I can see, the current implementation of NSUrlSessionHandler uses simple NSURLSessionDataTask under the hood. If you need specific upload a file you should be sure that the native layer supports this behavior.

There is NSURLSessionUploadTask in iOS for upload but we can't simply use it without reworking the native handler.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you need specific upload a file you should be sure that the native layer

I don't see why I need to do that. The normal http handlers does this just fine. Regardless, you're posting some stream,. and it's wrong to assume it's from the beginning of that stream, and that was all I was pointing out.

Choose a reason for hiding this comment

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

If that is true then the behaviour in the android equivalent of this class is wrong. See: AndroidMessageHandler.cs

if (stream.CanSeek)
    stream.Seek (0, SeekOrigin.Begin);

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup it would seem so

Copy link
Member

Choose a reason for hiding this comment

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

I think doing the same thing Android does is good enough for now, it's still better than the previous behavior.

@mandel-macaque
Copy link
Member

I'm going to block this since I want to get input from the dotnet team, I'll me looking at how the socket handler is implemented too.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@stephen-hawley
Copy link
Contributor

👀

@wcoder
Copy link
Contributor Author

wcoder commented Nov 23, 2022

@mandel-macaque Hi, Do you have some updates?

@rolfbjarne rolfbjarne added the community Community contribution ❤ label Dec 21, 2022
@wcoder
Copy link
Contributor Author

wcoder commented Jan 23, 2023

I'm going to block this since I want to get input from the dotnet team, I'll me looking at how the socket handler is implemented too.

@mandel-macaque Do you have any updates?

@DuncanMT
Copy link

Any news on this? This breaks the Polly retry library.

@wcoder wcoder requested a review from dotMorten May 12, 2023 21:51
@mandel-macaque
Copy link
Member

@DuncaMT bumping this in my todo, I'll take care of it ASAP.

@wcoder
Copy link
Contributor Author

wcoder commented Nov 20, 2023

Hi @mandel-macaque, sorry to bother you. May you have some time to review this PR?

Copy link
Contributor

Hi @{issueAuthor}. Due to inactivity, we will close this pull request in 7 days.

Copy link
Contributor

Hi @{issueAuthor}. This pull request was closed due to inactivity. Please let us know if you'd like to reopen it.

@wcoder
Copy link
Contributor Author

wcoder commented Feb 26, 2024

@mandel-macaque Could you please reopen this PR?

@microsoft-github-policy-service bot looks too buggy

@tipa
Copy link

tipa commented Feb 27, 2024

Would love to see some progress on this PR, since now the AndroidMessageHandler is also being fixed that already had stream rewind logic:
https://github.com/xamarin/xamarin-android/blob/a82ac4e5608b9745916db320f4ff36921d4d6dee/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L543-L561.
Once both PRs are merged and released, I could finally simplify my HTTP retry logic :)

Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@dotMorten
Copy link
Contributor

Agreed. This would be some awesome cleanup that'll improve our retry logic as well and save some ugly byte array copying to ensure things are retriable

@rolfbjarne
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 21a922c5fe199320f9be26b270de68251e2294bf [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11) passed 💻

All tests on macOS M1 - Mac Big Sur (11) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 21a922c5fe199320f9be26b270de68251e2294bf [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 170 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ install-source: All 1 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 7 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac-binding-project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 7 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (watchOS): All 4 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 21a922c5fe199320f9be26b270de68251e2294bf [PR build]

@rolfbjarne rolfbjarne removed the do-not-merge Do not merge this pull request label Feb 28, 2024
@rolfbjarne rolfbjarne merged commit 6ef7d9c into dotnet:main Feb 28, 2024
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix community Community contribution ❤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NSUrlSessionHandler loses Content of reused HttpRequestMessage
8 participants