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

Provide documentation and context information for NIOTooManyBytesError #2831

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

cmcgee1024
Copy link
Contributor

Motivation:

The NIOTooManyBytesError doesn't have any documentation for someone that encounters this error. Also, they have no idea the magnitude of the limit that was set to decide if the payload is an unreasonable size.

Modifications:

Provide documentation that explains the situation when the error occurs, which is the upTo limit of an AsyncSequence is exceeded. Describe one potential action, which is to increase this limit.

Provide the maxBytes in the error so that the user can gauge whether the upTo limit is already reasonable and the payload size is excessive, or the limit needs to be increased to suit more situations.

Result:

There will be documentation for the NIOTooManyBytesError so that if someone looks it up they will have a better understanding of the situation, and possible actions. The limit will be included in the error to give them an idea of the scale of the payload limit that is in place, or potentially the configuration value that they can change.

The NIOTooManyBytesError doesn't have any documentation for someone
that encounters this error. Provide documentation that explains the
situation when the error occurs, which is the upTo limit of an
AsyncSequence is exceeded. Describe one potential action, which
is to increase this limit.

The error doesn't give the end user any sense of magnitude of the
byte limit that has been exceeded. Provide the maxBytes in the error
so that the user can gauge whether the upTo limit is already
reasonable and the payload size is excessive, or the limit needs
to be increased to suit more situations.
@weissi weissi added the ⚠️ semver/major Breaks existing public API. label Aug 9, 2024
@cmcgee1024
Copy link
Contributor Author

@weissi would it preferable to provide a backward compatible init function and make maxBytes optional?

@weissi
Copy link
Member

weissi commented Aug 21, 2024

@weissi would it preferable to provide a backward compatible init function and make maxBytes optional?

Yes, we should not break SemVer major just for this. I'll let @Lukasa & @FranzBusch et al comment more on what API would be good

@weissi weissi requested a review from dnadoba August 21, 2024 20:02
Copy link
Member

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

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

We likely want to make two of these errors equal regardless of their value of the maxBytes property.

public struct NIOTooManyBytesError: Error, Hashable {
public init() {}
let maxBytes: Int?
Copy link
Member

Choose a reason for hiding this comment

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

This should be a var. no need to restrict it to a let as there are no invariants or similar that need to be verified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this should be public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's var and public, then what's a good way to prevent it from being mutated after the initial throw?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's no reason to prevent it being mutated. And indeed, given the init, you can't:

extension NIOTooManyBytesError {
   mutating func getOutOfMyWayFoolsIMutateWhatIWant(maxBytes: Int?) {
       self = .init(maxBytes: maxBytes)
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've updated it to be public mutable.

/// more bytes in a sequence than what was specified as the maximum. It could be that this upTo
/// limit should be increased, or that the sequence has unexpected content in it.
///
/// - maxBytes: (optional) current limit on the maximum number of bytes in the sequence
Copy link
Member

Choose a reason for hiding this comment

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

The docs for a property should be above the property.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This generally looks good, but I'd like to see the tests updated to validate that this is working properly.

Sources/NIOCore/AsyncAwaitSupport.swift Show resolved Hide resolved
public struct NIOTooManyBytesError: Error, Hashable {
public init() {}
let maxBytes: Int?
Copy link
Contributor

Choose a reason for hiding this comment

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

Also this should be public.

@@ -138,14 +139,22 @@ final class AsyncSequenceCollectTests: XCTestCase {
file: testCase.file,
line: testCase.line
)
if let tooManyBytesErr = error as? NIOTooManyBytesError {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should fail the test if the cast doesn't pass.

@@ -154,6 +163,14 @@ final class AsyncSequenceCollectTests: XCTestCase {
file: testCase.file,
line: testCase.line
)
if let tooManyBytesErr = error as? NIOTooManyBytesError {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should fail the test if the cast doesn't pass.

/// exceeds a certain threshold beyond which the content isn't matching an expected reasonable
/// size to be processed. This error is generally thrown when it is discovered that there are more
/// more bytes in a sequence than what was specified as the maximum. It could be that this upTo
/// limit should be increased, or that the sequence has unexpected content in it.
public struct NIOTooManyBytesError: Error, Hashable {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a custom Equatable and Hashable implementation that ignores maxBytes? == can just return true and hash(into:) can just hash a constant e.g. 0. Users are usually not interested in the specific maxBytes value but rather just that it is a NIOTooManyBytesError error.

Copy link
Member

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@Lukasa Lukasa added 🆕 semver/minor Adds new public API. and removed ⚠️ semver/major Breaks existing public API. labels Aug 27, 2024
@cmcgee1024
Copy link
Contributor Author

cmcgee1024 commented Aug 27, 2024

After looking through the various failures I see that there's a formatter failure. How best to run the formatter for this project to reformat the code? Homebrew installing the swift-format package yields an error about an unrecognized rule.

@Lukasa Lukasa merged commit e1b2a99 into apple:main Aug 28, 2024
27 of 29 checks passed
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Sep 10, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [apple/swift-nio](https://redirect.github.com/apple/swift-nio) | minor
| `2.70.0` -> `2.72.0` |

---

### Release Notes

<details>
<summary>apple/swift-nio (apple/swift-nio)</summary>

###
[`v2.72.0`](https://redirect.github.com/apple/swift-nio/releases/tag/2.72.0)

[Compare
Source](https://redirect.github.com/apple/swift-nio/compare/2.71.0...2.72.0)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### SemVer Minor

- Add .compact format to ByteBuffer's hexdump method by
[@&#8203;supersonicbyte](https://redirect.github.com/supersonicbyte) in
[https://github.com/apple/swift-nio/pull/2856](https://redirect.github.com/apple/swift-nio/pull/2856)

##### SemVer Patch

- Make `assumeIsolated` work with SerialExecutors that are backed by
EventLoops by
[@&#8203;fabianfett](https://redirect.github.com/fabianfett) in
[https://github.com/apple/swift-nio/pull/2865](https://redirect.github.com/apple/swift-nio/pull/2865)

#### New Contributors

- [@&#8203;supersonicbyte](https://redirect.github.com/supersonicbyte)
made their first contribution in
[https://github.com/apple/swift-nio/pull/2856](https://redirect.github.com/apple/swift-nio/pull/2856)

**Full Changelog**:
apple/swift-nio@2.71.0...2.72.0

###
[`v2.71.0`](https://redirect.github.com/apple/swift-nio/releases/tag/2.71.0)

[Compare
Source](https://redirect.github.com/apple/swift-nio/compare/2.70.0...2.71.0)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

##### SemVer Minor

- Adopt strict concurrency and Sendable in `NIOConcurrencyHelpers` by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2832](https://redirect.github.com/apple/swift-nio/pull/2832)
- Adopt strict concurrency in `_NIODataStructures` by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2835](https://redirect.github.com/apple/swift-nio/pull/2835)
- Provide documentation and context information for
`NIOTooManyBytesError` by
[@&#8203;cmcgee1024](https://redirect.github.com/cmcgee1024) in
[https://github.com/apple/swift-nio/pull/2831](https://redirect.github.com/apple/swift-nio/pull/2831)

##### SemVer Patch

- Adopt strict concurrency in `_NIOBase64` by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2838](https://redirect.github.com/apple/swift-nio/pull/2838)
- Remove symlinks from resources by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2841](https://redirect.github.com/apple/swift-nio/pull/2841)
- Fix global concurrency hook integration test by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2857](https://redirect.github.com/apple/swift-nio/pull/2857)

##### Other Changes

- Update wording from `ubuntu` to `Ubuntu` at README.md by
[@&#8203;lamtrinhdev](https://redirect.github.com/lamtrinhdev) in
[https://github.com/apple/swift-nio/pull/2830](https://redirect.github.com/apple/swift-nio/pull/2830)
- Update the triggers for the Semantic Version label check by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2833](https://redirect.github.com/apple/swift-nio/pull/2833)
- Add `.editorconfig` file by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2829](https://redirect.github.com/apple/swift-nio/pull/2829)
- Fix test availability by
[@&#8203;glbrntt](https://redirect.github.com/glbrntt) in
[https://github.com/apple/swift-nio/pull/2836](https://redirect.github.com/apple/swift-nio/pull/2836)
- Strict concurrency the early tests by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2840](https://redirect.github.com/apple/swift-nio/pull/2840)
- Fix `NIOFileSystem` flaky tests by
[@&#8203;gjcairo](https://redirect.github.com/gjcairo) in
[https://github.com/apple/swift-nio/pull/2842](https://redirect.github.com/apple/swift-nio/pull/2842)
- Improve `testTasksScheduledDuringShutdownAreAutomaticallyCancelled` by
[@&#8203;glbrntt](https://redirect.github.com/glbrntt) in
[https://github.com/apple/swift-nio/pull/2843](https://redirect.github.com/apple/swift-nio/pull/2843)
- Align benchmark scaling and minimum samples by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2839](https://redirect.github.com/apple/swift-nio/pull/2839)
- Explain why `ThreadLocalVariable` isn't Sendable. by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2845](https://redirect.github.com/apple/swift-nio/pull/2845)
- \[CI] Don't persist git credentials in CI by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2847](https://redirect.github.com/apple/swift-nio/pull/2847)
- \[CI] Mark the workspace as safe for the matrix job by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2848](https://redirect.github.com/apple/swift-nio/pull/2848)
- Pin DocC to below 1.4 by
[@&#8203;Lukasa](https://redirect.github.com/Lukasa) in
[https://github.com/apple/swift-nio/pull/2854](https://redirect.github.com/apple/swift-nio/pull/2854)
- \[CI] Make container images configurable in soundness and matrix jobs
… by [@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2851](https://redirect.github.com/apple/swift-nio/pull/2851)
- Update release.yml by
[@&#8203;FranzBusch](https://redirect.github.com/FranzBusch) in
[https://github.com/apple/swift-nio/pull/2850](https://redirect.github.com/apple/swift-nio/pull/2850)

#### New Contributors

- [@&#8203;lamtrinhdev](https://redirect.github.com/lamtrinhdev) made
their first contribution in
[https://github.com/apple/swift-nio/pull/2830](https://redirect.github.com/apple/swift-nio/pull/2830)
- [@&#8203;cmcgee1024](https://redirect.github.com/cmcgee1024) made
their first contribution in
[https://github.com/apple/swift-nio/pull/2831](https://redirect.github.com/apple/swift-nio/pull/2831)

**Full Changelog**:
apple/swift-nio@2.70.0...2.71.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config
help](https://redirect.github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://redirect.github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC43Mi4wIiwidXBkYXRlZEluVmVyIjoiMzguNzIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: cgrindel-self-hosted-renovate[bot] <139595543+cgrindel-self-hosted-renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants