Skip to content

Commit

Permalink
There are too many types of timeout here
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerkaraszewski committed Oct 3, 2023
1 parent d78ba89 commit 2502f9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,21 +845,27 @@ void BedrockServer::runCommand(unique_ptr<BedrockCommand>&& _command, bool isBlo
}

// Also, if we're shutting down or standing down, wait 1 second. This keeps the rest of the server from being blocked on commands that won't finish.
bool shuttingDown = false;
auto _syncNodeCopy = atomic_load(&_syncNode);
if (_shutdownState.load() != RUNNING || (_syncNodeCopy && _syncNodeCopy->getState() == SQLiteNodeState::STANDINGDOWN)) {
maxWaitUs = 1'000'000;
shuttingDown = true;
}

// Ok, go ahead and `poll`.
S_poll(fdm, maxWaitUs);


// The 3rd parameter to `postPoll` here is the total allowed idle time on this connection. We will kill connections that do nothing at all after 5 minutes normally,
// or after only 5 seconds when we're shutting down so that we can clean up and move along.
uint64_t ignore{0};
auto start = STimeNow();
command->postPoll(fdm, maxWaitUs, maxWaitUs / 1000);
command->postPoll(fdm, ignore, shuttingDown ? 5'000 : 300'000);
postPollCumulativeTime += (STimeNow() - start);
}

if (networkLoopCount) {
SINFO("Completed HTTPS request in " << networkLoopCount << " loops with " << postPollCumulativeTime << " total time in postPoll");
SINFO("Completed HTTPS request in " << networkLoopCount << " loops with " << postPollCumulativeTime << "us total time in postPoll");
}

// Get a DB handle to work on. This will automatically be returned when dbScope goes out of scope.
Expand Down
2 changes: 2 additions & 0 deletions libstuff/SHTTPSManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SStandaloneHTTPSManager : public STCPManager {
void prePoll(fd_map& fdm, Transaction& transaction);

// Default timeout for HTTPS requests is 5 minutes.This can be changed on any call to postPoll.
// This is a total amount of milliseconds of idle activity since the last send on a socket before killing it.
// The purpose of this is to be able to shut down when no activity is happening.
void postPoll(fd_map& fdm, Transaction& transaction, uint64_t& nextActivity, uint64_t timeoutMS = (5 * 60 * 1000));

// Close a transaction and remove it from our internal lists.
Expand Down

0 comments on commit 2502f9c

Please sign in to comment.