[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Nbd] Stop little server, stop!



The nbd-server from nbd-2.8.3 likes to fill up my logs with gigabytes of
"socket operation on non-socket".  What happens is this:

  - Server receives a new connection and forks a child

  - The child closes its copy of the server socket and proceeds to serve the
    connection

  - The remote client disconnects, so the child's handler loop exits

  - The child continues around the server loop (BUG!)

  - The child now thinks it is a server and tries to accept connections on
    its closed server socket

  - Child logs error messages forever or until the disk fills up, whichever
    comes first.

Patch against nbd-2.8.3:

--- nbd-server.c.old	2006-02-23 14:03:48.000000000 -0800
+++ nbd-server.c	2006-02-23 14:02:58.000000000 -0800
@@ -798,7 +798,7 @@ int copyonwrite_prepare(CLIENT* client)
  *
  * @param net A network socket connected to an nbd client
  **/
-void serveconnection(CLIENT *client) {
+int serveconnection(CLIENT *client) {
 	splitexport(client);

 	if (!client->server->expected_size) {
@@ -822,7 +822,7 @@ void serveconnection(CLIENT *client) {

 	setmysockopt(client->net);

-	mainloop(client);
+	return mainloop(client);
 }

 /**
@@ -986,7 +986,7 @@ int serveloop(SERVER* serve) {
 		close(serve->socket) ;
 #endif // NOFORK
 		msg2(LOG_INFO,"Starting to serve") ;
-		serveconnection(client);
+		return serveconnection(client);
 	}
 }




Reply to: