Skip to content

Commit

Permalink
Make rp attempt to connect a couple of times before giving up. This
Browse files Browse the repository at this point in the history
makes sense when indexing large projects with very small files (or .c
files which index very fast).
  • Loading branch information
Andersbakken committed Apr 29, 2015
1 parent a2b1735 commit d1a4728
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/ClangIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool ClangIndexer::exec(const String &data)
uint64_t id;
String socketFile;
Flags<IndexerJob::Flag> indexerJobFlags;
uint32_t connectTimeout;
uint32_t connectTimeout, connectAttempts;
int32_t niceValue;
Hash<uint32_t, Path> blockedFiles;
String dataDir;
Expand All @@ -91,6 +91,7 @@ bool ClangIndexer::exec(const String &data)
deserializer >> mVisitFileTimeout;
deserializer >> mIndexDataMessageTimeout;
deserializer >> connectTimeout;
deserializer >> connectAttempts;
deserializer >> niceValue;
deserializer >> sServerOpts;
deserializer >> mUnsavedFiles;
Expand Down Expand Up @@ -136,9 +137,14 @@ bool ClangIndexer::exec(const String &data)

Location::init(blockedFiles);
Location::set(mSourceFile, mSource.fileId);
if (!mConnection->connectUnix(socketFile, connectTimeout)) {
error("Failed to connect to rdm on %s (%dms timeout)", socketFile.constData(), connectTimeout);
return false;
while (true) {
if (mConnection->connectUnix(socketFile, connectTimeout))
break;
if (!--connectAttempts) {
error("Failed to connect to rdm on %s (%dms timeout)", socketFile.constData(), connectTimeout);
return false;
}
usleep(500 * 1000);
}
// mLogFile = fopen(String::format("/tmp/%s", mSourceFile.fileName()).constData(), "w");
mIndexDataMessage.setProject(mProject);
Expand Down
1 change: 1 addition & 0 deletions src/IndexerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ String IndexerJob::encode() const
<< static_cast<uint32_t>(options.rpVisitFileTimeout)
<< static_cast<uint32_t>(options.rpIndexDataMessageTimeout)
<< static_cast<uint32_t>(options.rpConnectTimeout)
<< static_cast<uint32_t>(options.rpConnectAttempts)
<< static_cast<int32_t>(options.rpNiceValue)
<< static_cast<uint32_t>(options.options)
<< unsavedFiles
Expand Down
4 changes: 2 additions & 2 deletions src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ class Server
Options()
: jobCount(0), headerErrorJobCount(0),
rpVisitFileTimeout(0), rpIndexDataMessageTimeout(0), rpConnectTimeout(0),
rpNiceValue(0), threadStackSize(0), maxCrashCount(0),
rpConnectAttempts(0), rpNiceValue(0), threadStackSize(0), maxCrashCount(0),
completionCacheSize(0), testTimeout(60 * 1000 * 5),
maxFileMapScopeCacheSize(512)
{}
Path socketFile, dataDir, argTransform;
Flags<Option> options;
int jobCount, headerErrorJobCount, rpVisitFileTimeout, rpIndexDataMessageTimeout,
rpConnectTimeout, rpNiceValue, threadStackSize, maxCrashCount,
rpConnectTimeout, rpConnectAttempts, rpNiceValue, threadStackSize, maxCrashCount,
completionCacheSize, testTimeout, maxFileMapScopeCacheSize;
List<String> defaultArguments, excludeFilters;
Set<String> blockedArguments;
Expand Down
11 changes: 11 additions & 0 deletions src/rdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void sigSegvHandler(int signal)
#define DEFAULT_RDM_MAX_FILE_MAP_CACHE_SIZE 500
#define DEFAULT_RP_INDEXER_MESSAGE_TIMEOUT 60000
#define DEFAULT_RP_CONNECT_TIMEOUT 0 // won't time out
#define DEFAULT_RP_CONNECT_ATTEMPTS 3
#define DEFAULT_COMPLETION_CACHE_SIZE 10
#define DEFAULT_MAX_CRASH_COUNT 5
#define XSTR(s) #s
Expand Down Expand Up @@ -91,6 +92,7 @@ static void usage(FILE *f)
" --no-rc|-N Don't load any rc files.\n"
" --no-startup-project|-o Don't restore the last current project on startup.\n"
" --rp-connect-timeout|-O [arg] Timeout for connection from rp to rdm in ms (0 means no timeout) (default " STR(DEFAULT_RP_CONNECT_TIMEOUT) ").\n"
" --rp-connect-attempts [arg] Number of times rp attempts to connect to rdm before giving up. (default " STR(DEFAULT_RP_CONNECT_ATTEMPTS) ").\n"
" --rp-indexer-message-timeout|-T [arg] Timeout for rp indexer-message in ms (0 means no timeout) (default " STR(DEFAULT_RP_INDEXER_MESSAGE_TIMEOUT) ").\n"
" --rp-nice-value|-a [arg] Nice value to use for rp (nice(2)) (default -1, e.g. not nicing).\n"
" --rp-visit-file-timeout|-Z [arg] Timeout for rp visitfile commands in ms (0 means no timeout) (default " STR(DEFAULT_RP_VISITFILE_TIMEOUT) ").\n"
Expand Down Expand Up @@ -184,6 +186,7 @@ int main(int argc, char** argv)
{ "rp-visit-file-timeout", required_argument, 0, 'Z' },
{ "rp-indexer-message-timeout", required_argument, 0, 'T' },
{ "rp-connect-timeout", required_argument, 0, 'O' },
{ "rp-connect-attempts", required_argument, 0, '\3' },
{ "rp-nice-value", required_argument, 0, 'a' },
{ "thread-stack-size", required_argument, 0, 'k' },
{ "suspend-rp-on-crash", required_argument, 0, 'q' },
Expand Down Expand Up @@ -312,6 +315,7 @@ int main(int argc, char** argv)
serverOpts.rpVisitFileTimeout = DEFAULT_RP_VISITFILE_TIMEOUT;
serverOpts.rpIndexDataMessageTimeout = DEFAULT_RP_INDEXER_MESSAGE_TIMEOUT;
serverOpts.rpConnectTimeout = DEFAULT_RP_CONNECT_TIMEOUT;
serverOpts.rpConnectAttempts = DEFAULT_RP_CONNECT_ATTEMPTS;
serverOpts.maxFileMapScopeCacheSize = DEFAULT_RDM_MAX_FILE_MAP_CACHE_SIZE;
serverOpts.rpNiceValue = INT_MIN;
serverOpts.options = Server::Wall|Server::SpellChecking;
Expand Down Expand Up @@ -416,6 +420,13 @@ int main(int argc, char** argv)
return 1;
}
break;
case '\3':
serverOpts.rpConnectAttempts = atoi(optarg);
if (serverOpts.rpConnectAttempts <= 0) {
fprintf(stderr, "Invalid argument to --rp-connect-attempts %s\n", optarg);
return 1;
}
break;
case 'k':
serverOpts.threadStackSize = atoi(optarg);
if (serverOpts.threadStackSize < 0) {
Expand Down

0 comments on commit d1a4728

Please sign in to comment.