Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit d3361d6

Browse files
Merge pull request #62 from Unity-Technologies/release/6.1.2
Release/6.1.2
2 parents d710bf5 + 96b312f commit d3361d6

22 files changed

+834
-669
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ node_modules/
66
coverage/
77
local-production.yml
88
.cache*/
9+
Dockerfile*
10+
.dockerignore

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v8.11.3
1+
v8.12.0

lib/cache/cache_fs.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CacheFS extends CacheBase {
123123
let deleteSize = 0;
124124
let deletedItemCount = 0;
125125
let deleteItems = [];
126-
let verb = dryRun ? 'Gathering' : 'Removing';
126+
const verb = dryRun ? 'Gathering' : 'Removing';
127127
let spinnerMessage = verb + ' expired files';
128128

129129
const progressData = () => {
@@ -184,7 +184,7 @@ class CacheFS extends CacheBase {
184184
needsSorted = false;
185185
}
186186

187-
let i = deleteItems[deleteItems.length - 1]; // i is the MRU out of the current delete list
187+
const i = deleteItems[deleteItems.length - 1]; // i is the MRU out of the current delete list
188188

189189
if (item.stats.atime < i.stats.atime) {
190190
deleteItems = helpers.insertSorted(item, deleteItems, (a, b) => {
@@ -361,11 +361,6 @@ class HashedWriteStream extends fs.WriteStream {
361361
super._write(data, encoding, cb);
362362
}
363363

364-
_writev (chunks, cb) {
365-
chunks.forEach(chunk => this._hash.update(chunk, 'ascii'));
366-
super._writev(chunks, cb);
367-
}
368-
369364
get byteHash() {
370365
return this._hash.digest();
371366
}

lib/client/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class CacheClient {
8585
* @returns {Promise<any>}
8686
*/
8787
quit() {
88+
if(!this._client) return Promise.resolve();
89+
8890
return new Promise(resolve => {
8991
this._client.once('close', () => resolve());
9092
this._client.end(cmd.quit);

lib/helpers.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const consts = require("./constants");
33
const dns = require('dns');
44
const path = require('path');
55
const fs = require('fs-extra');
6+
const ip = require('ip');
67

78
let logLevel = consts.LOG_TEST;
89

@@ -92,16 +93,23 @@ exports.isBuffer = function(obj) {
9293
* @returns {Promise<any>}
9394
*/
9495
exports.parseAndValidateAddressString = function(address, defaultPort) {
96+
if(ip.isV6Format(address) && !ip.isV4Format(address))
97+
return Promise.reject("IPV6 mirrors not supported");
98+
9599
// eslint-disable-next-line prefer-const
96100
let [host, port] = address.split(':');
101+
port = port || defaultPort;
97102

98103
port = parseInt(port);
99104
if(!port) port = defaultPort;
100105

106+
if(ip.isV4Format(host) || ip.isV6Format(host))
107+
return Promise.resolve({ host: host, port: port });
108+
101109
return new Promise((resolve, reject) => {
102-
dns.lookup(host, {family: 4, hints: dns.ADDRCONFIG}, (err, address) => {
110+
dns.lookup(host, {family: 4, hints: dns.ADDRCONFIG}, (err, ip) => {
103111
if(err) return reject(err);
104-
resolve({ host: address, port: port });
112+
resolve({ host: ip, port: port });
105113
});
106114
});
107115
};
@@ -212,10 +220,9 @@ function locationOf(item, array, compare, start, end) {
212220
start = start || 0;
213221
end = end || array.length;
214222

215-
let pivot = (start + end) >> 1;
216-
217-
let c = compare(item, array[pivot]);
218-
if (end - start <= 1) return c == -1 ? pivot - 1 : pivot;
223+
const pivot = (start + end) >> 1;
224+
const c = compare(item, array[pivot]);
225+
if (end - start <= 1) return c === -1 ? pivot - 1 : pivot;
219226

220227
switch (c) {
221228
case -1: return locationOf(item, array, compare, start, pivot);

lib/server/server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ class CacheServer {
6161

6262
const cmdProc = new CommandProcessor(self.cache);
6363

64-
// TODO: Prune mirror list to exclude the incoming socket address, to prevent looping transactions
6564
const mirrors = self._mirrors;
66-
6765
if(mirrors.length > 0) {
6866
cmdProc.on('onTransactionEnd', (trx) => {
69-
mirrors.forEach(m => m.queueTransaction(trx));
67+
mirrors.forEach(m => {
68+
if(m.address !== socket.remoteAddress)
69+
m.queueTransaction(trx);
70+
});
7071
});
7172
}
7273

lib/server/transaction_mirror.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ class TransactionMirror {
2121
this._cache = cache;
2222
this._queue = [];
2323
this._processing = false;
24-
this._queueProcessDelay = TransactionMirror.options.queueProcessDelay || PROCESS_DELAY_MS;
24+
this._queueProcessDelay = connectOptions.queueProcessDelay || TransactionMirror.options.queueProcessDelay || PROCESS_DELAY_MS;
2525

26-
const address = connectOptions.address;
26+
const host = connectOptions.host;
2727
const port = connectOptions.port;
28-
const idleTimeout = TransactionMirror.options.idleTimeout || CONNECT_IDLE_TIMEOUT_MS;
29-
this._client = new Client(address, port, {idleTimeout: idleTimeout});
28+
const idleTimeout = connectOptions.idleTimeout || TransactionMirror.options.idleTimeout || CONNECT_IDLE_TIMEOUT_MS;
29+
this._client = new Client(host, port, {idleTimeout: idleTimeout});
30+
helpers.log(consts.LOG_INFO, `[TransactionMirror] Mirroring transactions to ${host}:${port}`);
3031
}
3132

3233
static get options() {
@@ -38,6 +39,7 @@ class TransactionMirror {
3839
}
3940

4041
_connect() {
42+
helpers.log(consts.LOG_INFO, `[TransactionMirror] Connecting to ${this._connectOptions.host}:${this._connectOptions.port}`);
4143
return this._client.connect();
4244
}
4345

main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ function collect(val, memo) {
2929
const defaultCacheModule = config.get("Cache.defaultModule");
3030

3131
const processorOptions = config.get("Cache.options.processor");
32-
if(Array.isArray(processorOptions.putWhitelist) && processorOptions.putWhitelist.length){
32+
if(Array.isArray(processorOptions.putWhitelist) && processorOptions.putWhitelist.length) {
3333
helpers.log(consts.LOG_INFO, `PUT whitelist: ${processorOptions.putWhitelist}`);
34-
};
34+
}
3535

3636
program.description("Unity Cache Server")
3737
.version(VERSION)

0 commit comments

Comments
 (0)