Skip to content

Commit 7286710

Browse files
committed
make copies of Buffers coming from SSH to avoid weirdness owing to async queues
1 parent f1e51f4 commit 7286710

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/cloud/install/installer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ class CloudInstaller {
113113
message: 'invitation URL not found'
114114
});
115115
}).on('data', (data: Buffer) => {
116-
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(data));
116+
// Make a copy before passing to the async queue.
117+
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
117118
}).stderr.on('data', (data: Buffer) => {
118-
stderrRaw.handle(arraybuffers.bufferToArrayBuffer(data));
119+
// Make a copy before passing to the async queue.
120+
stderrRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
119121
});
120122
});
121123
}).on('error', (e: Error) => {

src/cloud/social/provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ class Connection {
524524

525525
this.tunnel_ = tunnel;
526526
tunnel.on('data', (buffer: Buffer) => {
527-
bufferQueue.handle(arraybuffers.bufferToArrayBuffer(buffer));
527+
// Make a copy before passing to the async queue.
528+
bufferQueue.handle(arraybuffers.bufferToArrayBuffer(new Buffer(buffer)));
528529
}).on('end', () => {
529530
log.debug('%1: tunnel end', this.name_);
530531
}).on('close', (hadError: boolean) => {
@@ -603,7 +604,8 @@ class Connection {
603604
});
604605

605606
stream.on('data', (data: Buffer) => {
606-
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(data));
607+
// Make a copy before passing to the async queue.
608+
stdoutRaw.handle(arraybuffers.bufferToArrayBuffer(new Buffer(data)));
607609
}).stderr.on('data', (data: Buffer) => {
608610
R({
609611
message: 'output received on STDERR: ' + data.toString()

0 commit comments

Comments
 (0)