Skip to content

Commit

Permalink
fix closing of connections
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Nov 21, 2024
1 parent c19f81a commit 4cb9beb
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions control_out_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ async function run (localHost, controlPort, proxyConfig) {
if (canConnect) {
console.log('🟠 Disabling new connections')
canConnect = false
if (connectionsJustClosed > 0) {
console.log('Closing', connectionsJustClosed, 'open connection(s)')
for (const connection of connections) {
try {
connection.close()
console.log('Closed:', connection.localAddr, '<->', connection.remoteAddr)
connectionsJustClosed++
} catch (e) {
if (e.name === 'BadResource') {
console.log('Already closed:', connection.localAddr, '<->', connection.remoteAddr)
connectionsAlreadyClosed++
} else {
throw e
}
}
if (connections.size > 0) {
console.log('Closing', connectionsJustClosed, 'open connection(s)')
for (const connection of connections) {
try {
connection.close()
console.log('Closed:', connection.localAddr, '<->', connection.remoteAddr)
connectionsJustClosed++
} catch (e) {
if (e.name === 'BadResource') {
console.log('Already closed:', connection.localAddr, '<->', connection.remoteAddr)
connectionsAlreadyClosed++
} else {
throw e
}
connections.delete(connection)
}
connections.delete(connection)
}
}
return respond(200, {
Expand Down

0 comments on commit 4cb9beb

Please sign in to comment.