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

Server control flow should close connection on DecoderException #2419

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

#2367 changed server-side control flow. After that, connection.write doesn't start before we received a request meta-data. As the result, all errors that happen during parsing of the meta-data do not reach WriteStreamSubscriber and can leave a connection in undefined state, when we logged an error but didn't clean up the channel state.

Modifications:

  • Close the channel if an error occurs on the Single of request meta-data;
  • Add tests to verify the expected behavior;

Result:

Channel is closed when an early request error happens, client doesn't hang forever.

@idelpivnitskiy
Copy link
Member Author

The plan for the next release is to revert #2367, cut the release, reapply #2367, then merge this fix.

@idelpivnitskiy
Copy link
Member Author

This PR will go in after #2367 is reverted back, see #2423.

final Completable exchange = requestSingle.flatMapCompletable(rawRequest -> {
final Completable exchange = requestSingle.whenOnError(t -> {
// If an error happened before we could start writing, we need to close the channel.
nettyChannel().close();
Copy link
Member

Choose a reason for hiding this comment

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

when we close under the hood it can be difficult for users to understand who initiated closure. Consider either:

  • moving this close operation into ErrorLoggingHttpSubscriber after it logs the reason
  • adding a comment that ErrorLoggingHttpSubscriber will log the exception if required.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I've moved closure to ErrorLoggingHttpSubscriber

@Scottmitch
Copy link
Member

lgtm after the above is addressed.

@idelpivnitskiy
Copy link
Member Author

I've reverted back server-side control flow as the first commit and applied a change of this PR as the second commit. Will use "Rebase and merge"

Motivation:

apple#2367 changed server-side control flow. After that, `connection.write`
doesn't start before we received a request meta-data. As the result, all
errors that happen during parsing of the meta-data do not reach
`WriteStreamSubscriber` and can leave a connection in undefined state,
when we logged an error but didn't clean up the channel state.

Modifications:

- Close the channel inside `ErrorLoggingHttpSubscriber` if it was not
closed already. It covers a case when an error occurs on the `Single` of
request meta-data;
- Add tests to verify the expected behavior;

Result:

Server channel is closed when an early request error happens, client
doesn't hang forever.
@idelpivnitskiy idelpivnitskiy merged commit a652c67 into apple:main Nov 18, 2022
@idelpivnitskiy idelpivnitskiy deleted the flow-control-fix branch November 18, 2022 21:56
idelpivnitskiy added a commit to idelpivnitskiy/servicetalk that referenced this pull request Dec 17, 2022
idelpivnitskiy added a commit to idelpivnitskiy/servicetalk that referenced this pull request Dec 17, 2022
idelpivnitskiy added a commit to idelpivnitskiy/servicetalk that referenced this pull request Dec 17, 2022
idelpivnitskiy added a commit that referenced this pull request Dec 17, 2022
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