Skip to content

Commit

Permalink
Merge pull request #22368 from mjibson/max-size-err
Browse files Browse the repository at this point in the history
pgwire: send client error on connection failure
  • Loading branch information
maddyblue authored Oct 13, 2023
2 parents 8767e7d + 593df95 commit 2189368
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/environmentd/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,8 @@ fn test_max_request_size() {
let param = std::iter::repeat("1").take(param_size).join("");
let mut client = server.connect(postgres::NoTls).unwrap();

// The specific error isn't forwarded to the client, the connection is just closed.
assert!(client.query(statement, &[&param]).is_err());
let err = client.query(statement, &[&param]).unwrap_db_error();
assert_contains!(err.message(), "request larger than");
assert!(client.is_valid(Duration::from_secs(2)).is_err());
}

Expand Down
17 changes: 16 additions & 1 deletion src/pgwire/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,22 @@ where
};

select! {
r = machine.run() => r,
r = machine.run() => {
// Errors produced internally (like MAX_REQUEST_SIZE being exceeded) should send an
// error to the client informing them why the connection was closed. We still want to
// return the original error up the stack, though, so we skip error checking during conn
// operations.
if let Err(err) = &r {
let _ = conn
.send(ErrorResponse::fatal(
SqlState::CONNECTION_FAILURE,
err.to_string(),
))
.await;
let _ = conn.flush().await;
}
r
},
_ = is_expired => {
conn
.send(ErrorResponse::fatal(SqlState::INVALID_AUTHORIZATION_SPECIFICATION, "authentication expired"))
Expand Down

0 comments on commit 2189368

Please sign in to comment.