You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Handle "Unexpected response type for remote procedure call: Close" on query stream opening (#759)
## Usage and product changes
Fix a rare `InternalError` returned by mistake when a client sends a
query request while the transaction is being closed. Now, an expected
"The transaction is closed and no further operation is allowed." error
is returned instead.
Additionally, wait for specific transaction responses in `rollback`,
`commit`, and `query` to solidify the protocol and ensure that the
server acts as expected.
## Implementation
We
[faced](https://discord.com/channels/665254494820368395/1301180015173435454/1379414371402256454)
this error when running a huge number of queries against a server that
eventually went to sleep. Presumably, this state led to the GRPC stream
interruption, and it "gracefully" stopped without errors. However, the
driver's code did not expect that it could happen right after the stream
opening request, while it should be considered a normal situation.
The source code where `Close` responses are generated:
```
async fn listen_loop(
mut grpc_source: Streaming<transaction::Server>,
collector: ResponseCollector,
shutdown_sink: UnboundedSender<()>,
) {
loop {
match grpc_source.next().await {
Some(Ok(message)) => collector.collect(message).await,
Some(Err(status)) => break collector.close_with_error(status.into()).await,
None => break collector.close().await, // <---- here, the stream has ended
}
}
shutdown_sink.send(()).ok();
}
async fn close(self) {
self.is_open.store(false);
let mut listeners = std::mem::take(&mut *self.callbacks.write().unwrap());
for (_, listener) in listeners.drain() {
listener.finish(Ok(TransactionResponse::Close)); // <--- here, the only `Close` response is sent
}
// ....
}
```
Additionally, we explicitly wait for *request's response type* or
*stream closed marker* with their correct processing for each other
transaction request in `transaction_stream`. For this, the commit
behavior of the server has been made more explicit:
typedb/typedb#7484
0 commit comments