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 broken encoding when publisher has no content #1345

Merged
merged 3 commits into from
Feb 4, 2021

Conversation

tkountis
Copy link
Contributor

@tkountis tkountis commented Feb 2, 2021

Motivation:

When a payload publisher on the response flow is not emitting any items, the encoder will not emit the header, thus a client will not be able to decode the response.

Modifications:

Make sure the header is emitted even for empty publishers.
Extra checks where added to skip encoding & headers when the request doesn't support body-messages.

Result:

Clients will be able to decode correctly encoded response payload, even when empty.

@tkountis tkountis self-assigned this Feb 2, 2021
@tkountis tkountis force-pushed the fix/broken-encoding-empty-pub branch from 8be98fa to d29f7a2 Compare February 2, 2021 14:56
@Scottmitch
Copy link
Member

test failure attributed to #999

Copy link
Member

@Scottmitch Scottmitch left a comment

Choose a reason for hiding this comment

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

Few comments/questions, can you update the commit message too: ... has not content -> ... has no content?

@Scottmitch
Copy link
Member

another test failure attributed to #999

@tkountis tkountis force-pushed the fix/broken-encoding-empty-pub branch from a1a0194 to ef971bc Compare February 3, 2021 11:48
@tkountis tkountis changed the title Fix broken encoding when publisher has not content Fix broken encoding when publisher has no content Feb 3, 2021
@tkountis tkountis requested a review from Scottmitch February 3, 2021 15:08

if (!headerWritten) {
// This will produce header bytes
output = newDeflaterOutputStream(stream);
Copy link
Member

Choose a reason for hiding this comment

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

can output be created up front too? I know this is Closable, but the existing approach doesn't account for Subscription.cancel() anyways and I would propose we revisit lifetime in a followup PR (for better isolation of changes).

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 output is created up front, then we need to allocate up-front too because it starts writing the header bytes immediately. This way we only allocate when we start consuming. I am re-working the overall lifetime + enhancements in a follow PR, let's keep further changes out of this one. I can revert if you prefer the old way, but I think this follows the 'cold' semantics of ST.

@@ -589,10 +571,10 @@ private void verifyCrc(Buffer in) throws IOException {
}

static class SwappableBufferOutputStream extends OutputStream {
@Nullable
Copy link
Member

Choose a reason for hiding this comment

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

if you don't wan't to worry about null you can initialize to EmptyBuffer.EMPTY_BUFFER

Copy link
Contributor Author

@tkountis tkountis Feb 4, 2021

Choose a reason for hiding this comment

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

I did consider that, but spotbugs starts complaining with RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT: Return value of method without side effect is ignored and I didn't won't to suppress it.

Copy link
Member

Choose a reason for hiding this comment

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

hum this seems like a general problem that we may want to address, but independent issue

@tkountis tkountis requested a review from Scottmitch February 4, 2021 12:13
@tkountis tkountis merged commit f839de4 into apple:main Feb 4, 2021
@tkountis tkountis deleted the fix/broken-encoding-empty-pub branch February 4, 2021 18:06
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