Skip to content

Commit a4af5ff

Browse files
Merge pull request #297 from jpogran/GH-240-tcp-retry-defaults
(GH-240) TCP Retry defaults
2 parents 5c31076 + 1815a65 commit a4af5ff

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
2121
- (maint) Automatically download languageserver on build and watch
2222
- (maint) Improve issue templates
2323
- ([GH-241](https://github.com/lingua-pupuli/puppet-vscode/issues/241)) Honor specified tcp port
24+
- ([GH-240](https://github.com/lingua-pupuli/puppet-vscode/issues/240)) Add TCP retry functionality
2425

2526
## 0.10.0 - 2018-03-29
2627

src/connection.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,65 @@ export class ConnectionManager implements IConnectionManager {
216216
): ServerOptions {
217217
let serverOptions: ServerOptions = function() {
218218
return new Promise((resolve, reject) => {
219+
const retries = 5;
220+
var attempt = 0;
219221
var client = new net.Socket();
222+
223+
const rconnect = () => { client.connect(port, address) };
224+
220225
client.connect(port, address, function() {
221-
logger.error(`[Puppet Lang Server Client] tcp connected`);
226+
logger.debug(`[Puppet Lang Server Client] tcp connected`);
222227
resolve({ reader: client, writer: client });
223228
});
229+
224230
client.on('error', function(err) {
225-
logger.error(`[Puppet Lang Server Client] ` + err);
226-
connectionManager.setConnectionStatus(
227-
`Could not start language client: ${err.message}`,
228-
ConnectionStatus.Failed
229-
);
230-
return null;
231+
232+
if(attempt === retries){
233+
logger.error(`[Puppet Lang Server Client] ` + `Could not start language client: ${err.message}`);
234+
connectionManager.setConnectionStatus(
235+
`Could not start language client: ${err.message}`,
236+
ConnectionStatus.Failed
237+
);
238+
239+
vscode.window.showErrorMessage(
240+
`Could not start language client: ${err.message}. Please click 'Troubleshooting Information' for resolution steps`,
241+
{ modal: false },
242+
{ title: 'Troubleshooting Information' }
243+
).then((item)=>{
244+
if (item === undefined){
245+
return;
246+
}
247+
if(item.title === 'Troubleshooting Information'){
248+
vscode.commands.executeCommand(
249+
'vscode.open',
250+
vscode.Uri.parse('https://github.com/lingua-pupuli/puppet-vscode#experience-a-problem')
251+
);
252+
}
253+
}
254+
);
255+
256+
return null;
257+
}else{
258+
attempt = attempt + 1;
259+
var message = `Timed out connecting to language server. Is the server running at ${address}:${port} ? Will wait timeout value before trying again`;
260+
switch(err.code){
261+
case 'ETIMEDOUT':
262+
message = `Timed out connecting to language server. Is the server running at ${address}:${port} ? Will wait timeout value before trying again`;
263+
break;
264+
case 'ECONNREFUSED':
265+
message = `Connect refused to language server. Is the server running at ${address}:${port} ? Will wait for 5 seconds before trying again`;
266+
break;
267+
default:
268+
message = `Connect refused to language server. Is the server running at ${address}:${port} ? Will wait for 5 seconds before trying again`;
269+
break;
270+
}
271+
vscode.window.showWarningMessage(message);
272+
logger.warning(message);
273+
setTimeout(rconnect, 5000);
274+
}
275+
231276
});
277+
232278
});
233279
};
234280
return serverOptions;

0 commit comments

Comments
 (0)