Handle ECONNRESET during a read request
This commit is contained in:
57
src/client.c
57
src/client.c
@@ -199,18 +199,25 @@ int client_read_request( struct client * client , struct nbd_request *out_reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fd_read_request(client->socket, &request_raw) == -1) {
|
if (fd_read_request(client->socket, &request_raw) == -1) {
|
||||||
if (errno == 0) {
|
switch( errno ){
|
||||||
debug("EOF reading request");
|
case 0:
|
||||||
return 0; /* neat point to close the socket */
|
debug( "EOF while reading request" );
|
||||||
}
|
return 0;
|
||||||
else {
|
case ECONNRESET:
|
||||||
/* FIXME: I've seen this happen, but I couldn't
|
debug( "Connection reset while"
|
||||||
* reproduce it so I'm leaving it here with a
|
" reading request" );
|
||||||
* better debug output in the hope it'll
|
return 0;
|
||||||
* spontaneously happen again. It should
|
default:
|
||||||
* *probably* be an error() call, but I want to
|
/* FIXME: I've seen this happen, but I
|
||||||
* be sure. */
|
* couldn't reproduce it so I'm leaving
|
||||||
fatal("Error reading request: %s", strerror( errno ));
|
* it here with a better debug output in
|
||||||
|
* the hope it'll spontaneously happen
|
||||||
|
* again. It should *probably* be an
|
||||||
|
* error() call, but I want to be sure.
|
||||||
|
* */
|
||||||
|
fatal("Error reading request: %d, %s",
|
||||||
|
errno,
|
||||||
|
strerror( errno ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +237,21 @@ int fd_write_reply( int fd, char *handle, int error )
|
|||||||
|
|
||||||
nbd_h2r_reply( &reply, &reply_raw );
|
nbd_h2r_reply( &reply, &reply_raw );
|
||||||
|
|
||||||
write( fd, &reply_raw, sizeof( reply_raw ) );
|
if( -1 == write( fd, &reply_raw, sizeof( reply_raw ) ) ) {
|
||||||
|
switch( errno ) {
|
||||||
|
case ECONNRESET:
|
||||||
|
error( "Connection reset while writing reply" );
|
||||||
|
break;
|
||||||
|
case EBADF:
|
||||||
|
fatal( "Tried to write to an invalid file descriptor" );
|
||||||
|
break;
|
||||||
|
case EPIPE:
|
||||||
|
error( "Remote end closed" );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fatal( "Unhandled error while writing: %d", errno );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -287,12 +308,14 @@ int client_request_needs_reply( struct client * client,
|
|||||||
switch (request.type)
|
switch (request.type)
|
||||||
{
|
{
|
||||||
case REQUEST_READ:
|
case REQUEST_READ:
|
||||||
FATAL_IF( client->entrusted,
|
ERROR_IF( client->entrusted,
|
||||||
"Received a read request after an entrust message.");
|
"Received a read request "
|
||||||
|
"after an entrust message.");
|
||||||
break;
|
break;
|
||||||
case REQUEST_WRITE:
|
case REQUEST_WRITE:
|
||||||
FATAL_IF( client->entrusted,
|
ERROR_IF( client->entrusted,
|
||||||
"Received a write request after an entrust message.");
|
"Received a write request "
|
||||||
|
"after an entrust message.");
|
||||||
/* check it's not out of range */
|
/* check it's not out of range */
|
||||||
if ( request.from+request.len > client->serve->size) {
|
if ( request.from+request.len > client->serve->size) {
|
||||||
debug("request read %ld+%d out of range",
|
debug("request read %ld+%d out of range",
|
||||||
|
Reference in New Issue
Block a user