Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #4984 into 3.11 #5084

Merged
merged 1 commit into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions common/SC_ServerBootDelayWarning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "SC_ServerBootDelayWarning.h"

#ifdef _WIN32
# include <iostream>
# include <thread>
# include <mutex>
# include <chrono>
# include <condition_variable>

static bool g_isServerBooted = false;
static std::mutex g_serverBootWarningMutex;
static std::condition_variable g_serverBootWarningConditionVariable;
static std::thread g_bootWarningThread;

static void displayWarningIfServerHasNotBooted() {
std::unique_lock<std::mutex> lock(g_serverBootWarningMutex);

if (!g_serverBootWarningConditionVariable.wait_for(lock, std::chrono::seconds(10),
[] { return g_isServerBooted; })) {
std::cout << "Server: possible boot delay." << std::endl;
std::cout << "On some Windows-based machines, Windows Defender sometimes ";
std::cout << "delays server boot by one minute." << std::endl;
std::cout << "You can add scsynth.exe and/or supernova.exe *processes* to ";
std::cout << "Windows Defender exclusion list to avoid this delay. It's safe." << std::endl;
}
}
#endif //_WIN32

void startServerBootDelayWarningTimer() {
#ifdef _WIN32
g_bootWarningThread = std::thread(displayWarningIfServerHasNotBooted);
#endif //_WIN32
}

void stopServerBootDelayWarningTimer() {
#ifdef _WIN32
{
const std::lock_guard<std::mutex> lock(g_serverBootWarningMutex);
g_isServerBooted = true;
}
g_serverBootWarningConditionVariable.notify_all();
g_bootWarningThread.join();
#endif //_WIN32
}
14 changes: 14 additions & 0 deletions common/SC_ServerBootDelayWarning.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Add a warning when Windows Defender delays scsynth boot by 60+ seconds
// cf. github issue #4368

#pragma once

// On Windows, starts a timer that will display a warning message
// after 10 seconds if the server has not booted,
// which may be due to Windows Defender.
// On other platforms, it does not do anything.
// Must be called at the start of the server boot sequence.
void startServerBootDelayWarningTimer();

// Must be called at the end of the server boot sequence.
void stopServerBootDelayWarningTimer();
1 change: 1 addition & 0 deletions server/scsynth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set(scsynth_sources
${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
${CMAKE_SOURCE_DIR}/common/Samp.cpp
${CMAKE_SOURCE_DIR}/common/sc_popen.cpp
${CMAKE_SOURCE_DIR}/common/SC_ServerBootDelayWarning.cpp
)

if(APPLE)
Expand Down
6 changes: 5 additions & 1 deletion server/scsynth/scsynth_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "SC_WorldOptions.h"
#include "SC_Version.hpp"
#include "SC_EventLoop.hpp"
#include "SC_ServerBootDelayWarning.h"
#include <cstring>
#include <stdio.h>
#include <stdarg.h>
Expand All @@ -44,7 +45,6 @@ inline int setlinebuf(FILE* stream) { return setvbuf(stream, (char*)0, _IONBF, 0

#endif


void Usage();
void Usage() {
WorldOptions defaultOptions;
Expand Down Expand Up @@ -126,6 +126,8 @@ void Usage() {


int scsynth_main(int argc, char** argv) {
startServerBootDelayWarningTimer();

setlinebuf(stdout);

EventLoop::setup();
Expand Down Expand Up @@ -340,6 +342,8 @@ int scsynth_main(int argc, char** argv) {
}
}

stopServerBootDelayWarningTimer();

if (options.mVerbosity >= 0) {
#ifdef NDEBUG
scprintf("SuperCollider 3 server ready.\n");
Expand Down
1 change: 1 addition & 0 deletions server/supernova/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(libsupernova_src
${CMAKE_SOURCE_DIR}/common/Samp.cpp
${CMAKE_SOURCE_DIR}/common/SC_fftlib.cpp
${CMAKE_SOURCE_DIR}/common/SC_StringParser.cpp
${CMAKE_SOURCE_DIR}/common/SC_ServerBootDelayWarning.cpp
server/buffer_manager.cpp
server/memory_pool.cpp
server/node_graph.cpp
Expand Down
7 changes: 7 additions & 0 deletions server/supernova/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <string>
#include <vector>

#include "SC_Win32Utils.h"
#include "SC_ServerBootDelayWarning.h"

#include <boost/filesystem/path.hpp>
#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -337,6 +340,8 @@ int main(int argc, char* argv[]) {
cout << "compiled for debugging" << endl;
#endif

startServerBootDelayWarningTimer();

// FIXME should have more granular error handling
try {
server_shared_memory_creator::cleanup(args.port());
Expand All @@ -346,6 +351,8 @@ int main(int argc, char* argv[]) {
set_plugin_paths(args, sc_factory.get());
load_synthdefs(server, args);

stopServerBootDelayWarningTimer();

if (!args.non_rt) {
try {
start_audio_backend(args);
Expand Down