Skip to content

Commit

Permalink
wait for connect in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
CamJN committed Mar 6, 2025
1 parent 8d7d222 commit 23a8711
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/agent/Core/Controller/CheckoutSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
#include "DataStructures/LString.h"
#include <Core/Controller.h>
#include <IOTools/IOUtils.h>
#include <Core/SpawningKit/ErrorRenderer.h>

/*************************************************************************
Expand Down Expand Up @@ -178,7 +179,21 @@ Controller::initiateSession(Client *client, Request *req) {
TRACE_POINT();
req->sessionCheckoutTry++;
try {
req->session->initiate();
if (!req->session->initiate()) {
unsigned long long timeout = 100000;
while (timeout > 0 && !waitUntilWritable(req->session->fd(), &timeout)){}
int connect_error = 0;
socklen_t connect_error_len = sizeof(connect_error);
if (timeout == 0) {
throw SystemException("Cannot connect socket", ETIMEDOUT);
} else if (-1 == getsockopt(req->session->fd(), SOL_SOCKET, SO_ERROR, &connect_error, &connect_error_len)) {
int err = errno;
throw SystemException("Cannot check socket status", err);
} else if (connect_error != 0) {
// connect_error uses the same error codes as errno
throw SystemException("Cannot connect socket", connect_error);
}
}
} catch (const SystemException &e2) {
UPDATE_TRACE_POINT();
if (req->sessionCheckoutTry < MAX_SESSION_CHECKOUT_TRY) {
Expand Down

0 comments on commit 23a8711

Please sign in to comment.