if (ret->d_tlsCtx) {
setupDoHClientProtocolNegotiation(ret->d_tlsCtx);
}
- if (g_outgoingDoHWorkerThreads == 0) {
+
+ if (g_configurationDone && g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads == 0) {
+ throw std::runtime_error("Error: setOutgoingDoHWorkerThreads() is set to 0 so no outgoing DoH worker thread is available to serve queries");
+ }
+
+ if (!g_outgoingDoHWorkerThreads || *g_outgoingDoHWorkerThreads == 0) {
g_outgoingDoHWorkerThreads = 1;
}
std::atomic<uint64_t> g_dohStatesDumpRequested{0};
std::unique_ptr<DoHClientCollection> g_dohClientThreads{nullptr};
-uint16_t g_outgoingDoHWorkerThreads{0};
+std::optional<uint16_t> g_outgoingDoHWorkerThreads{std::nullopt};
#ifdef HAVE_NGHTTP2
class DoHConnectionToBackend : public TCPConnectionToBackend
bool initDoHWorkers()
{
#ifdef HAVE_NGHTTP2
- if (g_outgoingDoHWorkerThreads > 0) {
- g_dohClientThreads = std::make_unique<DoHClientCollection>(g_outgoingDoHWorkerThreads);
- for (size_t idx = 0; idx < g_outgoingDoHWorkerThreads; idx++) {
+ if (!g_outgoingDoHWorkerThreads) {
+ /* Unless the value has been set to 0 explicitly, always start at least one outgoing DoH worker thread, in case a DoH backend
+ is added at a later time. */
+ g_outgoingDoHWorkerThreads = 1;
+ }
+
+ if (g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads > 0) {
+ g_dohClientThreads = std::make_unique<DoHClientCollection>(*g_outgoingDoHWorkerThreads);
+ for (size_t idx = 0; idx < *g_outgoingDoHWorkerThreads; idx++) {
g_dohClientThreads->addThread();
}
}
extern std::unique_ptr<DoHClientCollection> g_dohClientThreads;
extern std::atomic<uint64_t> g_dohStatesDumpRequested;
-extern uint16_t g_outgoingDoHWorkerThreads;
+extern std::optional<uint16_t> g_outgoingDoHWorkerThreads;
class TLSCtx;