Skip to content

Commit 90aaf8f

Browse files
committed
(maint) Enforce puppet loading order for facts and types
Previously facts and puppet types were loaded asynchronously which was causing an unseen issue whereby some types (e.g. Service, Package) were not seen as loaded. This was due to gem based facter loading the these types before the type loader. This would not normally be in an issue in Puppet Agent as native facter would not share the same ruby environment. However in development , or soon to add, PDK workflows, a gem based facter would be used. This commit changes the load order to synchronously load the types first and then load the facts, classes and functions asynchronously.
1 parent 8fdfb78 commit 90aaf8f

File tree

7 files changed

+15
-23
lines changed

7 files changed

+15
-23
lines changed

client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
88

99
- ([GH-225](https://github.com/jpogran/puppet-vscode/issues/225)) Readd Local Workspace comand line option
1010
- ([GH-231](https://github.com/jpogran/puppet-vscode/issues/231)) Make Document Validation asynchronous
11+
- ([GH-236](https://github.com/jpogran/puppet-vscode/issues/236)) Remove the preload option
1112

1213
## 0.9.0 - 2018-02-01
1314

client/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@
288288
"default": 10,
289289
"description": "The timeout to connect to the local Puppet Language Server"
290290
},
291-
"puppet.languageserver.preLoadPuppet": {
292-
"type": "boolean",
293-
"default": true,
294-
"description": "Initalize Puppet and Facter when local Puppet Language Server starts"
295-
},
296291
"puppet.languageserver.debugFilePath": {
297292
"type": "string",
298293
"default": "",

client/src/configuration.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import { IConnectionConfiguration, ConnectionType } from './interfaces';
66
import { ConnectionManager } from './connection';
77

88
export class ConnectionConfiguration implements IConnectionConfiguration {
9-
public type: ConnectionType = ConnectionType.Unknown;
9+
public type: ConnectionType = ConnectionType.Unknown;
1010
public host: string = undefined;
1111
public port: number = undefined;
1212
public timeout: number = undefined;
13-
public preLoadPuppet: boolean = undefined;
1413
public debugFilePath: string = undefined;
1514
public puppetAgentDir: string = undefined;
1615

@@ -20,9 +19,8 @@ export class ConnectionConfiguration implements IConnectionConfiguration {
2019
this.host = config['languageserver']['address'];
2120
this.port = config['languageserver']['port'];
2221
this.timeout = config['languageserver']['timeout'];
23-
this.preLoadPuppet = config['languageserver']['preLoadPuppet'];
2422
this.debugFilePath = config['languageserver']['debugFilePath'];
25-
23+
2624
this.puppetAgentDir = config['puppetAgentDir'];
2725
}
2826
}

client/src/connection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export class ConnectionManager implements IConnectionManager {
170170
}
171171
args.push('--port=' + this.connectionConfiguration.port);
172172
args.push('--timeout=' + this.connectionConfiguration.timeout);
173-
if (this.connectionConfiguration.preLoadPuppet == false) { args.push('--no-preload'); }
174173
if ((this.connectionConfiguration.debugFilePath != undefined) && (this.connectionConfiguration.debugFilePath != '')) {
175174
args.push('--debug=' + this.connectionConfiguration.debugFilePath);
176175
}
@@ -291,10 +290,10 @@ export class ConnectionManager implements IConnectionManager {
291290

292291
connectionManager.languageClient.sendRequest(messages.PuppetVersionRequest.type).then((versionDetails) => {
293292
lastVersionResponse = versionDetails
294-
if (!connectionManager.connectionConfiguration.preLoadPuppet || (versionDetails.factsLoaded &&
293+
if (versionDetails.factsLoaded &&
295294
versionDetails.functionsLoaded &&
296295
versionDetails.typesLoaded &&
297-
versionDetails.classesLoaded)) {
296+
versionDetails.classesLoaded) {
298297
clearInterval(handle);
299298
this.setConnectionStatus(lastVersionResponse.puppetVersion, ConnectionStatus.Running);
300299
resolve();

client/src/debugAdapter.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class DebugConfiguration implements IConnectionConfiguration {
4343
public host: string = "127.0.0.1";
4444
public port: number = 8082;
4545
public timeout: number = 10;
46-
public preLoadPuppet: boolean = false;
4746
public debugFilePath: string; // = "STDOUT";
4847
public puppetAgentDir: string;
4948
}
@@ -117,7 +116,7 @@ function startDebugServer(config:DebugConfiguration, debugLogger: ILogger) {
117116
if (localServer == null) { localServer = RubyHelper.getRubyEnvFromPuppetAgent(rubyfile, config, debugLogger); }
118117
// Commented out for the moment. This will be enabled once the configuration and exact user story is figured out.
119118
// if (localServer == null) { localServer = RubyHelper.getRubyEnvFromPDK(rubyfile, config, debugLogger); }
120-
119+
121120
if (localServer == null) {
122121
sendErrorMessage("Unable to find a valid ruby environment");
123122
process.exit(255);
@@ -145,7 +144,7 @@ function startDebugging(config:DebugConfiguration, debugLogger:ILogger) {
145144
debugServerProc.on('close', (exitCode) => {
146145
debugLogger.debug("Debug server terminated with exit code: " + exitCode);
147146
debugServerProc.kill();
148-
process.exit(exitCode);
147+
process.exit(exitCode);
149148
});
150149

151150
debugServerProc.on('error', (data) => {
@@ -155,19 +154,19 @@ function startDebugging(config:DebugConfiguration, debugLogger:ILogger) {
155154
process.on('SIGTERM', () => {
156155
debugLogger.debug("Received SIGTERM");
157156
debugServerProc.kill();
158-
process.exit(0);
157+
process.exit(0);
159158
});
160159

161160
process.on('SIGHUP', () => {
162161
debugLogger.debug("Received SIGHUP");
163162
debugServerProc.kill();
164-
process.exit(0);
163+
process.exit(0);
165164
});
166165

167166
process.on('exit', () => {
168167
debugLogger.debug("Received Exit");
169168
debugServerProc.kill();
170-
process.exit(0);
169+
process.exit(0);
171170
});
172171
}
173172

client/src/interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export interface IConnectionConfiguration {
2121
host: string;
2222
port: number;
2323
timeout: number;
24-
preLoadPuppet: boolean;
2524
debugFilePath: string;
2625
puppetAgentDir: string;
2726
}

server/lib/puppet-languageserver.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def self.parse(options)
5656
args[:connection_timeout] = timeout.to_i
5757
end
5858

59-
opts.on('-d', '--no-preload', 'Do not preload Puppet information when the language server starts. Default is to preload') do |_misc|
59+
opts.on('-d', '--no-preload', '** DEPRECATED ** Do not preload Puppet information when the language server starts. Default is to preload') do |_misc|
60+
puts '** WARNING ** Using "--no-preload" may cause Puppet Type loading to be incomplete.'
6061
args[:preload_puppet] = false
6162
end
6263

@@ -118,12 +119,12 @@ def self.init_puppet_worker(options)
118119

119120
log_message(:info, "Using Facter v#{Facter.version}")
120121
if options[:preload_puppet]
122+
log_message(:info, 'Preloading Puppet Types (Sync)...')
123+
PuppetLanguageServer::PuppetHelper.load_types
124+
121125
log_message(:info, 'Preloading Facter (Async)...')
122126
PuppetLanguageServer::FacterHelper.load_facts_async
123127

124-
log_message(:info, 'Preloading Puppet Types (Async)...')
125-
PuppetLanguageServer::PuppetHelper.load_types_async
126-
127128
log_message(:info, 'Preloading Functions (Async)...')
128129
PuppetLanguageServer::PuppetHelper.load_functions_async
129130

0 commit comments

Comments
 (0)