Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
97bade0
initial code for proxy
Ankit098 Jun 29, 2021
d0f54d9
modify proxy data object
Ankit098 Jun 30, 2021
7b71301
fixing retry logic for server ws connection
Ankit098 Jun 30, 2021
8f0402a
add check for options on proxy start
Ankit098 Jun 30, 2021
1977fbb
support client reconnection
Ankit098 Jul 1, 2021
9d9b5f0
add heartbeat ping
Ankit098 Jul 1, 2021
dc894e4
add(wip): sender class for sending to upstream
yashLadha Jul 6, 2021
7de671d
add(wip): Adding receiver mode
yashLadha Jul 6, 2021
769858b
add: cluster module and minor refactoring
yashLadha Jul 7, 2021
7e88725
chore: README addition to the code
yashLadha Jul 7, 2021
d67ff57
chore: refactored incoming connection handling for sender
yashLadha Jul 7, 2021
aaf8a2a
fix: wrong enqueue in receiver mode from client
yashLadha Jul 8, 2021
bfe0300
fix: modify request url with target in sender mode
yashLadha Jul 9, 2021
833f3f8
fix: connect to same url in receiver mode
yashLadha Jul 9, 2021
6394513
chore: ignore temp directory for commit
yashLadha Jul 9, 2021
e2ff37f
fix: cluster fork method in restarting workers
yashLadha Jul 9, 2021
7418438
chore: remove redundant information from child logger
yashLadha Jul 9, 2021
5157336
chore: added LLD file and minor changes to upstream
yashLadha Jul 13, 2021
d020553
fix: replace watchFile with watch
yashLadha Jul 13, 2021
4253a9e
chore: add diagram for receiver and sender mode
yashLadha Jul 13, 2021
5eed2c9
add: init doc v2 design
yashLadha Jul 14, 2021
3518ff1
chore: wip commit for defining the new design and implementation
yashLadha Jul 16, 2021
9c8d23d
:fire: Proxy v2 implementation init
Archish27 Jul 22, 2021
dba72bc
:art: Renamed method name and fixed setting context
Archish27 Jul 26, 2021
b96b2ae
:art: proxy v2 implementation and major bug fixes
Archish27 Jul 28, 2021
bf7677e
:white_check_mark: tests fixes for queue
Archish27 Jul 28, 2021
2691682
:art: EOL fixes
Archish27 Jul 28, 2021
1076f44
:art: updated package.json
Archish27 Jul 28, 2021
362b180
:white_check_mark: tests added for util
Archish27 Jul 29, 2021
a773631
:white_check_mark: Added tests for context
Aug 2, 2021
097b5ec
:white_check_mark: Added test for proxy
Aug 3, 2021
97c959a
:rotating_light: added eslint & fixes
Aug 3, 2021
e4e7882
:art: Added process handler and alerting
Aug 3, 2021
0cc226c
:art: Updated design & README.md
Archish27 Aug 3, 2021
7a0d12f
test: add tests for incoming ws
Ankit098 Aug 3, 2021
6a9ca87
test: add tests for outgoing ws
Ankit098 Aug 4, 2021
662ce50
Merge branch 'context_redesign' into context_redesign
Ankit098 Aug 4, 2021
92a7106
chore: eslint fixes for test files
Ankit098 Aug 4, 2021
1864a71
Merge pull request #1 from Ankit098/context_redesign
Archish27 Aug 4, 2021
0bc9c15
:bug: fix for sending alert
Archish27 Aug 4, 2021
891351b
:art: added settings.json for vscode
Archish27 Aug 4, 2021
68c536c
:art: eslint fixes
Archish27 Aug 4, 2021
2efa319
:art: eol fixes
Archish27 Aug 4, 2021
b4800e1
:white_check_mark: removed redundant close statement and test fixes
Archish27 Aug 5, 2021
cf87dbe
:art: Formatted code and added prettier
Archish27 Aug 5, 2021
5f9b6e6
:art: Added log rotate
Archish27 Aug 5, 2021
22d6833
:art: Updated logging to info
Archish27 Aug 5, 2021
f1c4962
:white_check_mark: Added tests
Archish27 Aug 5, 2021
81d624b
:art: Formatted dir structure & added lint fixes
Archish27 Aug 6, 2021
878a93c
:art: added typeSanity checks
Archish27 Aug 9, 2021
b5c3253
:art: Refactorred cluster.js and added worker kill timer
Archish27 Aug 9, 2021
6399e76
:art: Added worker timer and watching restart.txt in master
Archish27 Aug 9, 2021
523645d
:art: CLogging format updated
Archish27 Aug 9, 2021
b21bb07
:art: Added metric and test fixes
Archish27 Aug 10, 2021
907e6ae
:bug: fix for spawning workers
Archish27 Aug 11, 2021
cc551cc
:rotating_light: eol fixes
Archish27 Aug 11, 2021
860f56d
:art: ABinding http server in proxy and test fixes
Archish27 Aug 11, 2021
8d34b0e
:sparkle: Added workflow action
Archish27 Aug 15, 2021
568716e
:art: Added logic for Pproxy restart and chore fixes
Archish27 Aug 15, 2021
f590ebb
:memo: Updated README.md
Archish27 Aug 16, 2021
5b2ffff
:bug: fix for workflow actions
Archish27 Aug 16, 2021
7775532
:fire: removed redundant code
Archish27 Aug 16, 2021
affeded
:bug: fix for workflow actions
Archish27 Aug 16, 2021
6ff6e1a
:hammer: updated package.json
Archish27 Aug 16, 2021
acc971f
:bug: fix for workflow actions
Archish27 Aug 16, 2021
5c2440b
:art: Removed tabs
Archish27 Aug 16, 2021
69eceae
:white_check_mark: Added tests
Archish27 Aug 16, 2021
6ea81fa
:rotating_light: eslint fixes
Archish27 Aug 16, 2021
ef32c2c
:art: Update .prettierignore
Archish27 Aug 16, 2021
ae5ae35
:fire: Added log path from env variable
Archish27 Aug 17, 2021
260fea9
Merge branch 'context_redesign' of https://github.com/Archish27/ws-re…
Archish27 Aug 17, 2021
b5d66aa
:bug: fix for binding hostname and moving to node lts version
Archish27 Aug 18, 2021
dfcabeb
:art: Update docs/design.md
Archish27 Aug 18, 2021
39b739d
:art: Update docs/design.md
Archish27 Aug 18, 2021
e53e05c
:art: Update docs/design.md
Archish27 Aug 18, 2021
1612aa1
:bug: fix for restart path
Archish27 Aug 18, 2021
0b74130
Merge branch 'context_redesign' of https://github.com/Archish27/ws-re…
Archish27 Aug 18, 2021
32ff671
:bug: fix for alert and instrumentation
Archish27 Aug 18, 2021
fd427d5
:fire: removed messages meteric
Archish27 Aug 18, 2021
c29a20b
:white_check_mark: test fixes
Archish27 Aug 18, 2021
439ef8d
:fire: Updated changes for alert manager and instrumentation
Archish27 Aug 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
node: true,
commonjs: true,
es2021: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 12,
},
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
},
};
33 changes: 33 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Description

<!--- Describe your changes in detail -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My code follows the code style of this project.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
35 changes: 35 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
name: Lint and Test
steps:
- uses: actions/checkout@v2
name: Check out repository
- uses: actions/setup-node@v2
name: Setup Node.js
with:
node-version: '14.17.5'
- run: |
cp lib/config/config.json.sample lib/config/config.json
name: Setting up configuration
- run: |
npm ci
name: Installing Dependencies
- run: |
npm run eslint
name: Running ESLint checks on source
- run: |
npm run eslint:test
name: Running ESLint checks on tests
- run: |
npm run test
name: Running tests
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
tmp/
config.json
.nyc_output
logs/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.17.5
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logs/
.github/
.nyc_output/
.vscode/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"singleQuote": true,
"tabWidth": 2,
"endOfLine": "lf",
"semi": true,
"trailingComma": "es5",
"useTabs": false
}
12 changes: 12 additions & 0 deletions .rotate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
filter(data) {
return data.req;
},
output: {
path: './proxy.log',
options: {
path: './logs',
interval: '1d',
},
},
};
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "ws-reconnect-proxy",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/cluster.js",
"outputCapture": "std",
"console": "internalConsole",
"env": {
"NODE_ENV": "dev"
}
}
]
}
72 changes: 71 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
# ws-reconnect-proxy
Proxy Server that is between a ws server and a ws client. In case of either server / client disconnects graceful or otherwise - initiates/ supports reconnection .

Proxy Server that is between a ws server and a ws client. In case of either server / client disconnects graceful or otherwise - initiates/ supports reconnection.

Read more about [📝 design](docs/design.md)

### README Contents:

- [How to contribute](#how-to-contribute)
- [Development Internals](#development-internals)

### ✨ How to contribute

We are very happy to receive and merge your contributions into this repository!

To contribute via pull request, follow these steps:

1. Create an issue describing the feature you want to work on (or
have a look at the [issues](https://github.com/browserstack/ws-reconnect-proxy/issues))
2. Write your code, tests and format them with `npm run format`
3. Create a pull request describing your changes

Your pull request will be reviewed by a maintainer, who will get
back to you about any necessary changes or questions.

## ⚡️ Development Internals

### 🔨 Installing Dependencies

To install dependencies

```bash
npm install
```

### ✅ Running the Tests

In order to run the tests, make sure that you have installed dependencies:

```bash
npm run test
```

### 🎨 Formatting

To reformat files execute

```bash
npm run format
```

### 🚀 Run proxy

🔧 Before, executing proxy create the `config.json` by running the following command:

```bash
cp lib/config/config.json.sample lib/config/config.json
```

Additionally, you can configuration your proxy based on your needs. Refer here - [config.json.sample](lib/config/config.json.sample)

Then execute proxy by running the following command:

```bash
npm run start
```

_NOTE: By default it runs in `dev` environment you can configure your env by the following command:_

```bash
NODE_ENV=<env> node cluster.js
```
69 changes: 69 additions & 0 deletions cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

const cluster = require('cluster');
const { config } = require('./lib/config/constants.js');
const { watch } = require('fs');
const logger = require('./lib/util/loggerFactory.js');
const Proxy = require('./lib/core/Proxy.js');

const WORKER_CNT = config.workerVal;
const activeWorkers = [];

const path = require('path');

const RESTART_FILE = path.join(__dirname, 'tmp', 'restart.txt');

const forceKill = (worker) => {
if (!worker.isDead()) {
logger.info(`Worker ${worker.process.pid} is ${worker.state}, Killing it`);
worker.kill('SIGUSR2');
}
};

const disconnectOldWorkers = () => {
const len = activeWorkers.length;
for (let i = 0; i < len; i++) {
const oldWorker = activeWorkers.shift();
oldWorker.disconnect();
setTimeout(() => forceKill(oldWorker), config.workerKillTimer);
}
};

const spawnNewWorkers = () => {
if (cluster.isMaster) {
for (let i = 0; i < WORKER_CNT; ++i) {
const worker = cluster.fork();
worker.on('error', (err) => {
logger.error(`Received error event on ${worker.id} : ${err}`);
});
logger.info(`Created worker with id ${worker.id}`);
activeWorkers.push(worker);
}
}
};

if (cluster.isMaster) {
cluster.on('online', function (worker) {
logger.info(`Worker ${worker.process.pid} is online`);
});

cluster.on('exit', (worker, code, signal) => {
logger.info(
`worker ${worker.process.pid} died with signal ${signal} code ${code}`
);
if (activeWorkers.length == 0) spawnNewWorkers();
});

spawnNewWorkers();

let currTime = Date.now();
watch(RESTART_FILE, () => {
if (Date.now() > currTime) {
currTime = Date.now();
disconnectOldWorkers();
spawnNewWorkers();
}
});
} else {
new Proxy();
}
Loading