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 1ab7423
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion control_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function main () {
const service = new NamadaService(NAMADA, CHAIN_ID)
service.events.addEventListener('request-pause', async () => {
let canConnect = true
while (!(canConnect === false)) {
while (canConnect) {
console.log('🟠 Requesting pause until indexer catches up.')
const response = await fetch(`${NODE_OUT}/pause`)
const responseJson = await response.json()
Expand Down
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 1ab7423

Please sign in to comment.