Skip to content

Commit

Permalink
Catch UnhandledRejections in the forwarding connection
Browse files Browse the repository at this point in the history
  • Loading branch information
proAlexandr committed Aug 7, 2019
1 parent 562b831 commit f421314
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "kube-forwarder",
"version": "1.4.1",
"versionString": "1.4.1",
"version": "1.4.2",
"author": "Pixel Point <[email protected]>",
"homepage": "https://kube-forwarder.poxelpoint.io",
"description": "A tool for managing port forwarding configs for kubernetes clusters",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Layout/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
name: 'Toolbar',
computed: {
version: function() {
return process.env.NODE_ENV === 'test' ? '0.0.0' : packageJs.versionString
return process.env.NODE_ENV === 'test' ? '0.0.0' : packageJs.version
}
},
methods: {
Expand Down
27 changes: 17 additions & 10 deletions src/renderer/lib/k8s-port-forwarding-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import querystring from 'querystring'
import { WebSocketHandler } from '@kubernetes/client-node/dist/web-socket-handler'
import WebSocket from 'isomorphic-ws'

WebSocketHandler.restartableHandleStandardInput = async function (createWS, stdin, streamNum = 0) {
WebSocketHandler.restartableHandleStandardInput = function (createWS, stdin, streamNum = 0) {
const tryLimit = 3;
let queue = Promise.resolve()
let ws = null
Expand All @@ -19,17 +19,24 @@ WebSocketHandler.restartableHandleStandardInput = async function (createWS, stdi
}

let i = 0;
for (; i < tryLimit; ++i) {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(buff);
break;
} else {
ws = await createWS()

try {
for (; i < tryLimit; ++i) {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(buff);
break;
} else {
ws = await createWS()
}
}
} catch (e) {
// TODO: Сonsider to log network errors.
console.error(e)
stdin.end()
}

if (i >= tryLimit) {
throw new Error("can't send data to ws")
stdin.end()
}
}

Expand All @@ -45,7 +52,7 @@ WebSocketHandler.restartableHandleStandardInput = async function (createWS, stdi
}

export function patchForward (forward) {
forward.portForward = async function (namespace, podName, targetPorts, output, err, input) {
forward.portForward = function (namespace, podName, targetPorts, output, err, input) {
if (targetPorts.length === 0) {
throw new Error('You must provide at least one port to forward to.')
}
Expand Down Expand Up @@ -85,7 +92,7 @@ export function patchForward (forward) {
})
}

await WebSocketHandler.restartableHandleStandardInput(createWebSocket, input, 0)
WebSocketHandler.restartableHandleStandardInput(createWebSocket, input, 0)
}
}
/* eslint-enable */

0 comments on commit f421314

Please sign in to comment.