/// <summary> /// Starts the server with server yaml and waits for ready for 5 seconds. Use <see cref="Connect(string, ConnectionOptions)"/> instead. /// </summary> /// <param name="serverConfigYaml">Reindexer server configuration yaml</param> /// <param name="dbName"></param> /// <param name="user"></param> /// <param name="pass"></param> /// <param name="waitTimeoutForReady">Wait timeout for the server is ready. Default is 60sec.</param> /// <exception cref="TimeoutException">Throws if the server doesn't start in timeout interval.</exception> public void Start(string serverConfigYaml, string dbName, string user = null, string pass = null, TimeSpan?waitTimeoutForReady = null) { lock (_serverStartupLocker) //for not spinning extra threads and double checking lock. { if (Interlocked.Read(ref _isServerThreadStarted) == 1) //Interlocked for not extra locking in future to check is startup { return; } _serverThread = new Thread(() => { Interlocked.Exchange(ref _isServerThreadStarted, 1); try { DebugHelper.Log("Starting reindexer server..."); using (var configYaml = serverConfigYaml.GetHandle()) ReindexerBinding.start_reindexer_server(_pServer, configYaml); } catch (Exception e) { DebugHelper.Log(e.Message); } finally { Interlocked.Exchange(ref _isServerThreadStarted, 0); } }) { IsBackground = false }; _serverThread.Start(); } var waitTimeout = waitTimeoutForReady ?? TimeSpan.FromSeconds(60); var startTime = DateTime.UtcNow; while (ReindexerBinding.check_server_ready(_pServer) == 0) { if (DateTime.UtcNow - startTime > waitTimeout) { throw new TimeoutException($"Reindexer Embedded Server couldn't be started in {waitTimeout.TotalSeconds} seconds. Check configs."); } Thread.Sleep(100); } DebugHelper.Log("Reindexer server is started."); using (var dbNameRx = dbName.GetHandle()) using (var userRx = user.GetHandle()) using (var passRx = pass.GetHandle()) Assert.ThrowIfError(() => ReindexerBinding.get_reindexer_instance(_pServer, dbNameRx, userRx, passRx, ref Rx)); }