feat(grpc): add server-side stream validators#2602
Conversation
507787e to
e2f4bd0
Compare
c5c0e67 to
038f365
Compare
e2f4bd0 to
90ae261
Compare
038f365 to
89b8525
Compare
89b8525 to
355c9cd
Compare
dfawley
left a comment
There was a problem hiding this comment.
I'm trying to figure out how exactly this is going to be used.
Most likely it will be a server-side interceptor? In which case, when an error occurs, I would think we'd want to terminate the RPC with a status that indicates the cause of the problem.
Introduces `ServerSendStreamValidator` and `ServerRecvStreamValidator` to enforce strict gRPC semantics on server streams. These are intended to wrap raw transport streams before passing them to application-level handlers, ensuring that user-provided service logic cannot violate protocol rules. - `ServerSendStreamValidator` ensures proper response sequencing (Headers -> Messages -> Trailers) and prevents invalid state transitions, while fully supporting trailers-only responses. - `ServerRecvStreamValidator` safely manages terminal states, ensuring that any subsequent polls after stream completion consistently return an error to prevent undefined behavior. - Adds comprehensive unit tests to verify state machine correctness and protocol compliance.
355c9cd to
de7ee29
Compare
Yes on the server side interceptor. RecvStreamVal.. is somewhat straight forward. This'll be used closer to the protobuf API to ensure that we transition our generic stream request receiver to the protobuf API stream object. SendStreamVal.. is closer to the transport to validate the outgoing data after all other interceptors. I somewhat agree with the need for status. We need to update the Now that we are returning trailers instead of sending them, we need more details from SendStream to propagate to trailers . Does it sound okay to add |
I was expecting we'd just need an interceptor that can terminate the RPC underneath the handler when either the SendStream or RecvStream has any problem. I.e. we can't do stream validation via something that simply wraps each stream independently. |
I mean we are definitely gonna need an interceptor for this. But I was planning to separate it into two responsibilities , one for lifecycle for stream and another for lifecycle of handler. Something along the lines of But we might need some |
Sure but they will need to be linked, so it would make more sense to me to make them all together.
So you're thinking two different interceptors might be needed?
Yes we should make sure the RPC error includes an explanation of the protocol violation. I expect the interceptor would basically select on the handler future and a receive from a oneshot channel that the validator writes to, and then terminates with whichever status comes first, dropping the other future. |
|
So, we discussed offline. It'd make sense for both stream and handler validation to be a part of the same PR. I initially thought we'd need different handlers, but based on my progress so far, I believe a single one suffices.
Since , we don't expose error status from sendstream or recvstream right now, we cannot propagate anything beyond an arbitrary "internal error: stream broken" . Would you want to tweak our stream APIs to be able to propagate errors Err(Status) or Err(String) instead of Err() |
Introduces
ServerSendStreamValidatorandServerRecvStreamValidatorto enforce strict gRPC semantics on server streams. These are intended to wrap raw transport streams before passing them to application-level handlers, ensuring that user-provided service logic cannot violate protocol rules.ServerSendStreamValidatorensures proper response sequencing (Headers -> Messages -> Trailers) and prevents invalid state transitions, while fully supporting trailers-only responses.ServerRecvStreamValidatorsafely manages terminal states, ensuring that any subsequent polls after stream completion consistently return an error to prevent undefined behavior.This is recreation of #2595 to allow using a stacked PR workflow