Skip to content

Commit e88568f

Browse files
committed
remove cloud installer connection retry loop
1 parent daecb8d commit e88568f

File tree

1 file changed

+77
-82
lines changed

1 file changed

+77
-82
lines changed

src/cloud/install/installer.ts

Lines changed: 77 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ require('../social/monkey/process');
55
import arraybuffers = require('../../arraybuffers/arraybuffers');
66
import linefeeder = require('../../net/linefeeder');
77
import logging = require('../../logging/logging');
8-
import promises = require('../../promises/promises');
98
import queue = require('../../handler/queue');
109

1110
// https://github.com/borisyankov/DefinitelyTyped/blob/master/ssh2/ssh2-tests.ts
@@ -54,92 +53,88 @@ class CloudInstaller {
5453
debug: undefined
5554
};
5655

57-
let numAttempts = 0;
58-
return promises.retryWithExponentialBackoff(() => {
59-
log.debug('connection attempt %1...', (++numAttempts));
60-
return new Promise<string>((F, R) => {
61-
const connection = new Client();
62-
connection.on('ready', () => {
63-
log.debug('logged into server');
64-
65-
const stdoutRaw = new queue.Queue<ArrayBuffer, void>();
66-
const stdout = new linefeeder.LineFeeder(stdoutRaw);
67-
stdout.setSyncHandler((line: string) => {
68-
log.debug('STDOUT: %1', line);
69-
// Search for the URL anywhere in the line so we will
70-
// continue to work in the face of minor changes
71-
// to the install script.
72-
if (line.indexOf(INVITATION_PREFIX) === 0) {
73-
const inviteJson = line.substring(INVITATION_PREFIX.length);
74-
try {
75-
F(JSON.parse(inviteJson));
76-
} catch (e) {
77-
R({
78-
message: 'could not parse invite: ' + inviteJson
79-
});
80-
}
81-
} else if (line.indexOf(PROGRESS_PREFIX) === 0) {
82-
const tokens = line.split(' ');
83-
if (tokens.length < 2) {
84-
log.warn('could not parse progress update');
85-
} else {
86-
const progress = parseInt(tokens[1], 10);
87-
this.dispatchEvent_('progress', progress);
88-
}
89-
} else if (line.indexOf(STATUS_PREFIX) === 0) {
90-
this.dispatchEvent_('status', line);
91-
}
92-
});
93-
94-
const stderrRaw = new queue.Queue<ArrayBuffer, void>();
95-
const stderr = new linefeeder.LineFeeder(stderrRaw);
96-
stderr.setSyncHandler((line: string) => {
97-
log.error('STDERR: %1', line);
98-
});
99-
100-
connection.exec(INSTALL_COMMAND, (e: Error, stream: ssh2.Channel) => {
101-
if (e) {
102-
connection.end();
56+
return new Promise<string>((F, R) => {
57+
const connection = new Client();
58+
connection.on('ready', () => {
59+
log.debug('logged into server');
60+
61+
const stdoutRaw = new queue.Queue<ArrayBuffer, void>();
62+
const stdout = new linefeeder.LineFeeder(stdoutRaw);
63+
stdout.setSyncHandler((line: string) => {
64+
log.debug('STDOUT: %1', line);
65+
// Search for the URL anywhere in the line so we will
66+
// continue to work in the face of minor changes
67+
// to the install script.
68+
if (line.indexOf(INVITATION_PREFIX) === 0) {
69+
const inviteJson = line.substring(INVITATION_PREFIX.length);
70+
try {
71+
F(JSON.parse(inviteJson));
72+
} catch (e) {
10373
R({
104-
message: 'could not execute command: ' + e.message
74+
message: 'could not parse invite: ' + inviteJson
10575
});
106-
return;
10776
}
108-
stream.on('end', () => {
109-
stdout.flush();
110-
stderr.flush();
111-
connection.end();
112-
R({
113-
message: 'invitation URL not found'
114-
});
115-
}).on('data', (data: Buffer) => {
116-
// Make a copy before passing to the async queue.
117-
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
118-
}).stderr.on('data', (data: Buffer) => {
119-
// Make a copy before passing to the async queue.
120-
stderrRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
77+
} else if (line.indexOf(PROGRESS_PREFIX) === 0) {
78+
const tokens = line.split(' ');
79+
if (tokens.length < 2) {
80+
log.warn('could not parse progress update');
81+
} else {
82+
const progress = parseInt(tokens[1], 10);
83+
this.dispatchEvent_('progress', progress);
84+
}
85+
} else if (line.indexOf(STATUS_PREFIX) === 0) {
86+
this.dispatchEvent_('status', line);
87+
}
88+
});
89+
90+
const stderrRaw = new queue.Queue<ArrayBuffer, void>();
91+
const stderr = new linefeeder.LineFeeder(stderrRaw);
92+
stderr.setSyncHandler((line: string) => {
93+
log.error('STDERR: %1', line);
94+
});
95+
96+
connection.exec(INSTALL_COMMAND, (e: Error, stream: ssh2.Channel) => {
97+
if (e) {
98+
connection.end();
99+
R({
100+
message: 'could not execute command: ' + e.message
121101
});
102+
return;
103+
}
104+
stream.on('end', () => {
105+
stdout.flush();
106+
stderr.flush();
107+
connection.end();
108+
R({
109+
message: 'invitation URL not found'
110+
});
111+
}).on('data', (data: Buffer) => {
112+
// Make a copy before passing to the async queue.
113+
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
114+
}).stderr.on('data', (data: Buffer) => {
115+
// Make a copy before passing to the async queue.
116+
stderrRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
122117
});
123-
}).on('error', (e: Error) => {
124-
// This occurs when:
125-
// - user supplies the wrong username or password
126-
// - host cannot be reached, e.g. non-existant hostname
127-
R({
128-
message: 'could not login: ' + e.message
129-
});
130-
}).on('end', () => {
131-
log.debug('connection end');
132-
R({
133-
message: 'connection end without invitation URL'
134-
});
135-
}).on('close', (hadError: boolean) => {
136-
log.debug('connection close, with%1 error', (hadError ? '' : 'out'));
137-
R({
138-
message: 'connection close without invitation URL'
139-
});
140-
}).connect(connectConfig);
141-
});
142-
}, MAX_CONNECTION_INTERVAL_MS, INITIAL_CONNECTION_INTERVAL_MS);
118+
});
119+
}).on('error', (e: Error) => {
120+
// This occurs when:
121+
// - user supplies the wrong username or password
122+
// - host cannot be reached, e.g. non-existant hostname
123+
R({
124+
message: 'could not login: ' + e.message
125+
});
126+
}).on('end', () => {
127+
log.debug('connection end');
128+
R({
129+
message: 'connection end without invitation URL'
130+
});
131+
}).on('close', (hadError: boolean) => {
132+
log.debug('connection close, with%1 error', (hadError ? '' : 'out'));
133+
R({
134+
message: 'connection close without invitation URL'
135+
});
136+
}).connect(connectConfig);
137+
});
143138
}
144139
}
145140

0 commit comments

Comments
 (0)