Comparing version 1.5.3 to 1.6.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [1.6.0][] - 2021-03-15 | ||
- Implmenetn port re-bind | ||
- Disable Nagle's algorithm if configured | ||
- Read timeouts from config (remove hardcoded constants) | ||
- Refactor and improve code style | ||
- Add typing for Metacom class | ||
## [1.5.3][] - 2021-02-28 | ||
@@ -73,3 +81,4 @@ | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v1.5.3...HEAD | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v1.6.0...HEAD | ||
[1.6.0]: https://github.com/metarhia/metacom/compare/v1.5.3...v1.6.0 | ||
[1.5.3]: https://github.com/metarhia/metacom/compare/v1.5.2...v1.5.3 | ||
@@ -76,0 +85,0 @@ [1.5.2]: https://github.com/metarhia/metacom/compare/v1.5.1...v1.5.2 |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const https = require('https'); | ||
const worker = require('worker_threads'); | ||
const { threadId } = require('worker_threads'); | ||
@@ -14,5 +14,3 @@ const metautil = require('metautil'); | ||
const SHUTDOWN_TIMEOUT = 5000; | ||
const SHORT_TIMEOUT = 500; | ||
const LONG_RESPONSE = 30000; | ||
@@ -34,9 +32,26 @@ const receiveBody = async (req) => { | ||
this.semaphore = new Semaphore(concurrency, queue.size, queue.timeout); | ||
const { threadId } = worker; | ||
this.balancer = balancer && threadId === 1; | ||
const skipBalancer = balancer ? 1 : 0; | ||
this.port = this.balancer ? balancer : ports[threadId - skipBalancer - 1]; | ||
this.server = null; | ||
this.ws = null; | ||
this.protocol = protocol; | ||
this.host = host; | ||
this.bind(); | ||
} | ||
bind() { | ||
const { config, application, port, host } = this; | ||
const { protocol, timeouts, nagle = true } = config; | ||
const transport = protocol === 'http' || this.balancer ? http : https; | ||
const listener = this.listener.bind(this); | ||
this.server = transport.createServer({ ...application.cert }, listener); | ||
if (!nagle) { | ||
this.server.on('connection', (socket) => { | ||
socket.setNoDelay(true); | ||
}); | ||
} | ||
this.server.on('listening', () => { | ||
application.console.info(`Listen port ${port} in worker ${threadId}`); | ||
}); | ||
this.ws = new ws.Server({ server: this.server }); | ||
@@ -53,5 +68,10 @@ this.ws.on('connection', async (connection, req) => { | ||
}); | ||
this.protocol = protocol; | ||
this.host = host; | ||
this.server.listen(this.port, host); | ||
this.ws.on('error', (err) => { | ||
if (err.code !== 'EADDRINUSE') return; | ||
application.console.warn(`Address in use: ${host}:${port}, retry...`); | ||
setTimeout(() => { | ||
this.bind(); | ||
}, timeouts.bind); | ||
}); | ||
this.server.listen(port, host); | ||
} | ||
@@ -71,3 +91,3 @@ | ||
channel.destroy(); | ||
}, LONG_RESPONSE); | ||
}, this.config.timeouts.request); | ||
@@ -141,3 +161,3 @@ res.on('close', () => { | ||
} | ||
await metautil.delay(SHUTDOWN_TIMEOUT); | ||
await metautil.delay(this.config.timeouts.stop); | ||
this.closeChannels(); | ||
@@ -144,0 +164,0 @@ } |
{ | ||
"name": "metacom", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -36,2 +36,3 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access", | ||
"main": "metacom.js", | ||
"types": "types/metacom.d.ts", | ||
"browser": { | ||
@@ -46,5 +47,6 @@ "./metacom.js": "./dist/metacom.js" | ||
"scripts": { | ||
"test": "npm run lint && node ./test/unit.js && node ./test/integration.js ", | ||
"lint": "eslint . && prettier -c \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.yml\"", | ||
"fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.yml\"" | ||
"test": "npm run lint && npm run types && node ./test/unit.js && node ./test/integration.js", | ||
"types": "tsc -p types/tsconfig.json", | ||
"lint": "eslint . && prettier -c \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.yml\" \"**/*.ts\"", | ||
"fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.yml\" \"**/*.ts\"" | ||
}, | ||
@@ -55,7 +57,8 @@ "engines": { | ||
"dependencies": { | ||
"metautil": "^3.5.0", | ||
"ws": "^7.4.3" | ||
"metautil": "^3.5.1", | ||
"ws": "^7.4.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^7.21.0", | ||
"@types/node": "^14.14.35", | ||
"eslint": "^7.22.0", | ||
"eslint-config-metarhia": "^7.0.1", | ||
@@ -66,4 +69,5 @@ "eslint-config-prettier": "^8.1.0", | ||
"metatests": "^0.7.2", | ||
"prettier": "^2.2.1" | ||
"prettier": "^2.2.1", | ||
"typescript": "^4.2.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30453
751
9
Updatedmetautil@^3.5.1
Updatedws@^7.4.4