Skip to content

Commit

Permalink
fix(proxy): handle undefined _remote Socket
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Aug 20, 2019
1 parent 68017db commit 0caae29
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion garden-service/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function createProxy(garden: Garden, log: LogEntry, service: Service, spec

const server = createServer((local) => {
let _remote: Socket
let localDidClose = false

const getRemote = async () => {
if (!_remote) {
Expand Down Expand Up @@ -115,7 +116,13 @@ async function createProxy(garden: Garden, log: LogEntry, service: Service, spec
_remote.on("error", (err) => {
log.debug(`Remote socket error: ${err.message}`)
})

// Local connection was closed while remote connection was being created
if (localDidClose) {
_remote.end()
}
}

return _remote
}

Expand Down Expand Up @@ -153,7 +160,8 @@ async function createProxy(garden: Garden, log: LogEntry, service: Service, spec
})

local.on("close", () => {
_remote.end()
_remote && _remote.end()
localDidClose = true
})

local.on("error", (err) => {
Expand Down

0 comments on commit 0caae29

Please sign in to comment.