Skip to content

Commit 7209881

Browse files
committed
[Macros] Send termination signal to macro plugin
When shutting down, the plugin, we send SIGTERM, then wait(2) on it. But we observed some cases the compiler waits for the plugin process exit for long time. To resolve that, send an empty message to the plugin and let them exit itself. rdar://160820381
1 parent 9883477 commit 7209881

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/swift/AST/PluginRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class LoadedExecutablePlugin : public CompilerPlugin {
179179
: CompilerPlugin(ExecutablePath),
180180
LastModificationTime(LastModificationTime),
181181
disableSandbox(disableSandbox){};
182+
~LoadedExecutablePlugin();
182183

183184
/// The last modification time of 'ExecutablePath' when this object is
184185
/// created.

lib/AST/PluginRegistry.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ PluginRegistry::loadExecutablePlugin(StringRef path, bool disableSandbox) {
172172
return storage.get();
173173
}
174174

175+
LoadedExecutablePlugin::~LoadedExecutablePlugin() {
176+
if (Process) {
177+
// If the process is alive, send an empty message as the termination signal.
178+
// The plugin should exit itself when receiving it.
179+
if (auto error = sendMessage(""))
180+
llvm::consumeError(std::move(error));
181+
Process.reset();
182+
}
183+
}
184+
175185
llvm::Error LoadedExecutablePlugin::spawnIfNeeded() {
176186
if (Process) {
177187
// NOTE: We don't check the mtime here because 'stat(2)' call is too heavy.

0 commit comments

Comments
 (0)