mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
fix: drain the connection socket on a protocol error (#1422)
Signed-off-by: Andy Dunstall <andydunstall@hotmail.co.uk>
This commit is contained in:
parent
69e6ad799a
commit
7ec5bd912c
2 changed files with 18 additions and 2 deletions
|
@ -505,8 +505,24 @@ void Connection::ConnectionFlow(FiberSocketBase* peer) {
|
||||||
DCHECK(memcache_parser_);
|
DCHECK(memcache_parser_);
|
||||||
orig_builder->SendProtocolError("bad command line format");
|
orig_builder->SendProtocolError("bad command line format");
|
||||||
}
|
}
|
||||||
error_code ec2 = peer->Shutdown(SHUT_RDWR);
|
|
||||||
|
// Shut down the servers side of the socket to send a FIN to the client
|
||||||
|
// then keep draining the socket (discarding any received data) until
|
||||||
|
// the client closes the connection.
|
||||||
|
//
|
||||||
|
// Otherwise the clients write could fail (or block), so they would never
|
||||||
|
// read the above protocol error (see issue #1327).
|
||||||
|
error_code ec2 = peer->Shutdown(SHUT_WR);
|
||||||
LOG_IF(WARNING, ec2) << "Could not shutdown socket " << ec2;
|
LOG_IF(WARNING, ec2) << "Could not shutdown socket " << ec2;
|
||||||
|
if (!ec2) {
|
||||||
|
while (true) {
|
||||||
|
// Discard any received data.
|
||||||
|
io_buf_.Clear();
|
||||||
|
if (!peer->Recv(io_buf_.AppendBuffer())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FetchBuilderStats(stats_, orig_builder);
|
FetchBuilderStats(stats_, orig_builder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ auto RedisParser::ConsumeArrayLen(Buffer str) -> Result {
|
||||||
return BAD_ARRAYLEN;
|
return BAD_ARRAYLEN;
|
||||||
case OK:
|
case OK:
|
||||||
if (len < -1 || len > kMaxArrayLen) {
|
if (len < -1 || len > kMaxArrayLen) {
|
||||||
VLOG_IF(1, len > kMaxArrayLen) << "Multi bulk len is too big " << len;
|
LOG_IF(WARNING, len > kMaxArrayLen) << "Multi bulk len is too big " << len;
|
||||||
|
|
||||||
return BAD_ARRAYLEN;
|
return BAD_ARRAYLEN;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue