Disconnect between forked process and client
-
Hi all,
I have QCoreApplication server running on Linux, server fork itself when new connection is made from client
@
void Ccbox::incomingConnection(qintptr handle) {
qDebug()<<"Ccbox::incomingConnection";
pid_t PID=fork();
if(PID==0) {
this->close();
this->startNetwork(handle);
} else {
qDebug()<<"Ccbox::incomingConnection another process started";
}
}
@"this->close()" is to close child process to listen to port like parent, then pointer "handle" is passed to function that creates socket
@
socket=new QSslSocket(this);
if(!socket->setSocketDescriptor(socketDescriptor)) {
qDebug() <<"setSocketError:"<<socket->error();
return;
}
qDebug()<<"ssl supported:"<<socket->supportsSsl();
qDebug()<<"peerAddress:"<<socket->peerAddress();
socket->addCaCertificates(Zm().sslCA+Zm().sslCACert);
socket->setPrivateKey(Zm().sslFiles+Zm().sslKey);
socket->setLocalCertificate(Zm().sslFiles+Zm().sslCert);
socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
socket->startServerEncryption();
@this is QSslSocket so some cert options are set and connection is encrypted.
The problem is that my forked server always ends up in defunct state "[ccbox-demo] <defunct>" after connection is closed between server and client and server makes qApp->quit();
Connection close is initiated by client with disconnectFromHost and on both ends I can see socket is entering state: QAbstractSocket::UnconnectedState, 5 seconds later forked server makes qApp->quit() and ends up in defunct state.
I think is what I don't understand is this:
When I check with lsof command, right after I start client and fork server it shows that both parent and child server are connected to the client:
@
ccbox-dem 21347 7u IPv4 2439080 0t0 TCP *:4321 (LISTEN)
ccbox-dem 21347 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (ESTABLISHED)
ccbox-big 21349 10u IPv4 2440519 0t0 TCP localhost:38669->localhost:4321 (ESTABLISHED)
ccbox-dem 21351 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (ESTABLISHED)
@and after client is closed parent server is still connected to the client waiting in CLOSE_WAIT state
@
ccbox-dem 21347 7u IPv4 2439080 0t0 TCP *:4321 (LISTEN)
ccbox-dem 21347 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (CLOSE_WAIT)
@What should I do in parent server to close this connection right after child server has started ? Or is this some other problem? I need to get rid of these defunct processes
Best Regards
Marek -
Really, no one knows anything about it?
Marek