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

optional max payload size for ByteToMessageDecoder #957

Merged
merged 4 commits into from
Apr 11, 2019

Conversation

tomerd
Copy link
Member

@tomerd tomerd commented Apr 8, 2019

Motivation:

ByteToMessageDecoder aggregate data in memory as part of their normal operation. the ability to limit how much they aggregate is critical in many real-life applications

Modifications:

  • add optional maximumBufferSize argument to ByteToMessageDecoder initializer
  • test for buffer size when maximumBufferSize is set and throw ByteToMessageDecoderError.payloadTooLarge error

Result:

users can limit how much memory ByteToMessageDecoder takes and handle the exception on their end

@tomerd tomerd requested a review from weissi April 8, 2019 23:29
Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

thanks, this looks really good! A couple of small things though

Sources/NIO/Codec.swift Outdated Show resolved Hide resolved
Sources/NIO/Codec.swift Outdated Show resolved Hide resolved
Sources/NIO/Codec.swift Outdated Show resolved Hide resolved
@weissi weissi added the ⚠️ semver/major Breaks existing public API. label Apr 8, 2019
Sources/NIO/Codec.swift Outdated Show resolved Hide resolved
@tomerd
Copy link
Member Author

tomerd commented Apr 9, 2019

@weissi @Lukasa feedback addressed + rebased. still one open question re the timing of the check. i can go either way, tho slightly prefer to do it early

@tomerd tomerd removed the ⚠️ semver/major Breaks existing public API. label Apr 9, 2019
Sources/NIO/Codec.swift Outdated Show resolved Hide resolved
@weissi weissi added the 🆕 semver/minor Adds new public API. label Apr 10, 2019
@tomerd
Copy link
Member Author

tomerd commented Apr 10, 2019

@weissi updated

tomerd added 3 commits April 10, 2019 12:00
Motivation:

ByteToMessageDecoder aggregate data in memory as part of their normal operation. the ability to limit how much they aggregate is critical in many real-life applications

Modifications:

* add optional maximumBufferSize argument to ByteToMessageDecoder initializer
* test for buffer size when maximumBufferSize is set and throw ByteToMessageDecoderError.payloadTooLarge error

Result:

users can limit how much memory ByteToMessageDecoder takes and handle the exception on their end
@tomerd tomerd force-pushed the master branch 2 times, most recently from c6b1073 to e8220b6 Compare April 10, 2019 19:02
Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Thanks @tomerd . That looks great to me!

@Lukasa Lukasa added this to the 2.1.0 milestone Apr 11, 2019
@Lukasa Lukasa merged commit e32a436 into apple:master Apr 11, 2019
weissi added a commit to weissi/swift-nio that referenced this pull request May 17, 2019
Motivation:

In apple#957 we accidentally broke the API just a little bit. We turned the
`ByteToMessageHandler.init` from

    public init(_ decoder: Decoder)

into

    public init(_ decoder: Decoder, maximumBufferSize: Int? = nil)

This looks totally benign and in almost all cases because of the default
argument, you wouldn't notice the API breakage. However, it's possible
to write code that works in NIO 2.0.0 but breaks in NIO 2.1.0. For
example

    let g: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init
    let h: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init(_:)

Modifications:

According to SemVer, this releases a patch that unbreaks the public API.

Result:

No API breakages (checked with `swift-api-digester` which also found the
breakage in the first place).
weissi added a commit that referenced this pull request May 17, 2019
Motivation:

In #957 we accidentally broke the API just a little bit. We turned the
`ByteToMessageHandler.init` from

    public init(_ decoder: Decoder)

into

    public init(_ decoder: Decoder, maximumBufferSize: Int? = nil)

This looks totally benign and in almost all cases because of the default
argument, you wouldn't notice the API breakage. However, it's possible
to write code that works in NIO 2.0.0 but breaks in NIO 2.1.0. For
example

    let g: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init
    let h: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init(_:)

Modifications:

According to SemVer, this releases a patch that unbreaks the public API.

Result:

No API breakages (checked with `swift-api-digester` which also found the
breakage in the first place).
weissi added a commit that referenced this pull request May 17, 2019
Motivation:

In #957 we accidentally broke the API just a little bit. We turned the
`ByteToMessageHandler.init` from

    public init(_ decoder: Decoder)

into

    public init(_ decoder: Decoder, maximumBufferSize: Int? = nil)

This looks totally benign and in almost all cases because of the default
argument, you wouldn't notice the API breakage. However, it's possible
to write code that works in NIO 2.0.0 but breaks in NIO 2.1.0. For
example

    let g: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init
    let h: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init(_:)

Modifications:

According to SemVer, this releases a patch that unbreaks the public API.

Result:

No API breakages (checked with `swift-api-digester` which also found the
breakage in the first place).
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.

3 participants