Increased HTTP timeout to 10 seconds, removed no longer needed debug messages, fix unexpected disconnects deadlocking the proxy connections.
This commit is contained in:
parent
41d24ceee1
commit
79b5562123
1 changed files with 5 additions and 13 deletions
|
@ -161,7 +161,6 @@ namespace Connector_HTTP{
|
||||||
//check if a connection exists, and if not create one
|
//check if a connection exists, and if not create one
|
||||||
conn_mutex.lock();
|
conn_mutex.lock();
|
||||||
if (!connconn.count(uid)){
|
if (!connconn.count(uid)){
|
||||||
std::cout << "Creating connection" << std::endl;
|
|
||||||
connconn[uid] = new ConnConn(new Socket::Connection("/tmp/mist/http_"+connector));
|
connconn[uid] = new ConnConn(new Socket::Connection("/tmp/mist/http_"+connector));
|
||||||
connconn[uid]->conn->setBlocking(false);//do not block on spool() with no data
|
connconn[uid]->conn->setBlocking(false);//do not block on spool() with no data
|
||||||
}
|
}
|
||||||
|
@ -176,23 +175,20 @@ namespace Connector_HTTP{
|
||||||
}
|
}
|
||||||
conn_mutex.unlock();
|
conn_mutex.unlock();
|
||||||
|
|
||||||
std::cout << "Locking connection" << std::endl;
|
|
||||||
//lock the mutex for this connection, and handle the request
|
//lock the mutex for this connection, and handle the request
|
||||||
tthread::lock_guard<tthread::mutex> guard(connconn[uid]->in_use);
|
tthread::lock_guard<tthread::mutex> guard(connconn[uid]->in_use);
|
||||||
//if the server connection is dead, handle as timeout.
|
//if the server connection is dead, handle as timeout.
|
||||||
if (!connconn.count(uid) || !connconn[uid]->conn->connected()){
|
if (!connconn.count(uid) || !connconn[uid]->conn->connected()){
|
||||||
std::cout << "Dimeout" << std::endl;
|
|
||||||
Handle_Timeout(H, conn);
|
Handle_Timeout(H, conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Forwarding connection" << std::endl;
|
|
||||||
//forward the original request
|
//forward the original request
|
||||||
connconn[uid]->conn->Send(request);
|
connconn[uid]->conn->Send(request);
|
||||||
connconn[uid]->lastuse = 0;
|
connconn[uid]->lastuse = 0;
|
||||||
unsigned int timeout = 0;
|
unsigned int timeout = 0;
|
||||||
//wait for a response
|
//wait for a response
|
||||||
std::cout << "Waiting connection" << std::endl;
|
while (connconn.count(uid) && connconn[uid]->conn->connected() && conn->connected()){
|
||||||
while (connconn.count(uid) && connconn[uid]->conn->connected()){
|
conn->spool();
|
||||||
if (connconn[uid]->conn->spool()){
|
if (connconn[uid]->conn->spool()){
|
||||||
//check if the whole response was received
|
//check if the whole response was received
|
||||||
if (H.Read(connconn[uid]->conn->Received())){
|
if (H.Read(connconn[uid]->conn->Received())){
|
||||||
|
@ -200,8 +196,8 @@ namespace Connector_HTTP{
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//keep trying unless the timeout triggers
|
//keep trying unless the timeout triggers
|
||||||
if (timeout++ > 50){
|
if (timeout++ > 100){
|
||||||
std::cout << "Timeout" << std::endl;
|
std::cout << "[10s timeout triggered]" << std::endl;
|
||||||
Handle_Timeout(H, conn);
|
Handle_Timeout(H, conn);
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
|
@ -209,21 +205,18 @@ namespace Connector_HTTP{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!connconn.count(uid) || !connconn[uid]->conn->connected()){
|
if (!connconn.count(uid) || !connconn[uid]->conn->connected() || !conn->connected()){
|
||||||
//failure, disconnect and sent error to user
|
//failure, disconnect and sent error to user
|
||||||
std::cout << "Failure" << std::endl;
|
|
||||||
Handle_Timeout(H, conn);
|
Handle_Timeout(H, conn);
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
//success, check type of response
|
//success, check type of response
|
||||||
if (H.GetHeader("Content-Length") != ""){
|
if (H.GetHeader("Content-Length") != ""){
|
||||||
//known length - simply re-send the request with added headers and continue
|
//known length - simply re-send the request with added headers and continue
|
||||||
std::cout << "Known success" << std::endl;
|
|
||||||
H.SetHeader("X-UID", uid);
|
H.SetHeader("X-UID", uid);
|
||||||
conn->Send(H.BuildResponse("200", "OK"));
|
conn->Send(H.BuildResponse("200", "OK"));
|
||||||
}else{
|
}else{
|
||||||
//unknown length
|
//unknown length
|
||||||
std::cout << "Unknown success" << std::endl;
|
|
||||||
H.SetHeader("X-UID", uid);
|
H.SetHeader("X-UID", uid);
|
||||||
conn->Send(H.BuildResponse("200", "OK"));
|
conn->Send(H.BuildResponse("200", "OK"));
|
||||||
//continue sending data from this socket and keep it permanently in use
|
//continue sending data from this socket and keep it permanently in use
|
||||||
|
@ -237,7 +230,6 @@ namespace Connector_HTTP{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Completing connection" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the name of the HTTP connector the given request should be served by.
|
/// Returns the name of the HTTP connector the given request should be served by.
|
||||||
|
|
Loading…
Add table
Reference in a new issue