Skip to content

[binder] Fix server-side recv_trailing_metadata#27184

Merged
TaWeiTu merged 1 commit intogrpc:masterfrom
TaWeiTu:fix-recv-trailing-metadata
Sep 10, 2021
Merged

[binder] Fix server-side recv_trailing_metadata#27184
TaWeiTu merged 1 commit intogrpc:masterfrom
TaWeiTu:fix-recv-trailing-metadata

Conversation

@TaWeiTu
Copy link
Copy Markdown
Contributor

@TaWeiTu TaWeiTu commented Aug 30, 2021

According to the transport explainer, the server-side recv_trailing_metadata should not be completed before sending trailing metadata to the client.

Depends on #27182.

@TaWeiTu TaWeiTu added the release notes: no Indicates if PR should not be in release notes label Aug 30, 2021
@TaWeiTu TaWeiTu force-pushed the fix-recv-trailing-metadata branch from 7ab7547 to 8764e86 Compare August 30, 2021 17:48
@TaWeiTu TaWeiTu requested review from ctiller and sifmelcara August 30, 2021 18:10
@TaWeiTu TaWeiTu marked this pull request as draft August 31, 2021 02:04
Copy link
Copy Markdown
Contributor

@sifmelcara sifmelcara left a comment

Choose a reason for hiding this comment

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

The transport explainer said "Further examples include the idea that the server logic expects to not complete recv_trailing_metadata until after it actually sends trailing metadata since it would have already found this out by seeing a NULL’ed recv_message. This is considered part of the transport's duties in preserving orders."

However I don't really understand why, would you mind to explain?

Comment on lines +56 to +61
// Trailing metadata marks the end of one-side of the stream. Thus, after
// receiving trailing metadata from the other-end, we know that there will
// never be in-coming message data anymore, and all recv_message callbacks
// (as well as recv_initial_metadata callback, if there's any) registered will
// never be satisfied. This function cancels all such callbacks gracefully
// (with GRPC_ERROR_NONE) to avoid being blocked waiting for them.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrong comment location?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is the place it should be. Can you elaborate why it's at the wrong location?

// for them.
virtual void CancelRecvMessageCallbacksDueToTrailingMetadata(
StreamIdentifier id) = 0;
// Remove all entries associated with stream number `id`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrong comment location?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 184 to 197
InitialMetadataCallbackType cb = nullptr;
{
grpc_core::MutexLock l(&m_);
auto iter = initial_metadata_cbs_.find(id);
if (iter != initial_metadata_cbs_.end()) {
cb = std::move(iter->second);
initial_metadata_cbs_.erase(iter);
}
trailing_metadata_recvd_.insert(id);
}
if (cb != nullptr) {
// The registered callback will never be satisfied. Cancel it.
cb(absl::CancelledError(""));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably want a separate member function for readability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@TaWeiTu
Copy link
Copy Markdown
Contributor Author

TaWeiTu commented Sep 1, 2021

However I don't really understand why, would you mind to explain?

I don't quite understand the reason either, but I can give more context on the problem this would cause. From what I've seen, in for example a unary call setting, ServerContext::IsCancelled() will be true at the very beginning of the service without this PR, which is incorrect. This is because client sends initial metadata, message and trailing metadata at once in this case, and we will complete server-side recv_trailing_metadata prior to actually finishing the RPC procedure (where we return the final status to clients via send_trailing_metadata).

@TaWeiTu TaWeiTu force-pushed the fix-recv-trailing-metadata branch 2 times, most recently from 77a7827 to 1d666e5 Compare September 7, 2021 09:08
@TaWeiTu TaWeiTu marked this pull request as ready for review September 7, 2021 09:12
Copy link
Copy Markdown
Contributor

@sifmelcara sifmelcara left a comment

Choose a reason for hiding this comment

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

Although it does not address any real issue, I think it is ok to merge, just make sure your fuzzing target are still happy with these change

The code become more and more complex though, we will need to find time to refactor them if we are not going to rewrite the transport in near future

@TaWeiTu
Copy link
Copy Markdown
Contributor Author

TaWeiTu commented Sep 8, 2021

Although it does not address any real issue, I think it is ok to merge, just make sure your fuzzing target are still happy with these change

Hmm, why isn't it addressing any issue? The (new) tests in #27179 would fail without this due to the reason I outlined above.

The code become more and more complex though, we will need to find time to refactor them if we are not going to rewrite the transport in near future

Agree.

@sifmelcara
Copy link
Copy Markdown
Contributor

Hmm, why isn't it addressing any issue? The (new) tests in #27179 would fail without this due to the reason I outlined above.

Ah, ok! I missed that

@TaWeiTu TaWeiTu force-pushed the fix-recv-trailing-metadata branch 4 times, most recently from 22916bd to 6bfda58 Compare September 9, 2021 13:16
@TaWeiTu TaWeiTu enabled auto-merge (squash) September 9, 2021 13:17
@TaWeiTu TaWeiTu disabled auto-merge September 9, 2021 14:43
According to the [transport
explainer](https://grpc.github.io/grpc/core/md_doc_core_transport_explainer.html),
the server-side `recv_trailing_metadata` should not be completed before
sending trailing metadata to the client.
@TaWeiTu TaWeiTu force-pushed the fix-recv-trailing-metadata branch from 6bfda58 to f46f03b Compare September 10, 2021 02:57
@TaWeiTu TaWeiTu merged commit fa2d217 into grpc:master Sep 10, 2021
ashithasantosh pushed a commit to ashithasantosh/grpc that referenced this pull request Sep 10, 2021
According to the [transport explainer](https://grpc.github.io/grpc/core/md_doc_core_transport_explainer.html), the server-side `recv_trailing_metadata` should not be completed before sending trailing metadata to the client.
lidizheng pushed a commit to lidizheng/grpc that referenced this pull request Sep 23, 2021
According to the [transport explainer](https://grpc.github.io/grpc/core/md_doc_core_transport_explainer.html), the server-side `recv_trailing_metadata` should not be completed before sending trailing metadata to the client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/core release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants