Skip to content

Commit

Permalink
feat: improve stop logic to close all open http/2 connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-tkachenko committed Dec 11, 2023
1 parent 153744e commit 80fb4de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Prxi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ export class Prxi {
s.destroy();
this.sockets.delete(s);
});

this.proxies.forEach(p => {
p.http2?.closeAllConnections();
});
}

server.close((err) => {
Expand All @@ -578,10 +582,14 @@ export class Prxi {
return rej(err);
}

this.proxies.forEach(p => {
p.http2?.closeAllConnections();
});

this.logInfo('Prxi stopped');
res();
});
});
this.logInfo('Prxi stopped');
} else {
this.logInfo('Prxi stopping skipped, not running');
}
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/Http2ProxyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class Http2ProxyHandler {
return connection;
}


/**
* Close connection
* @param session
Expand All @@ -57,6 +56,16 @@ export class Http2ProxyHandler {
}
}

/**
* Close all connections
*/
public closeAllConnections(): void {
this.connections.forEach((connection) => {
connection.close();
});
this.connections = new Map();
}

/**
* Proxy request
* @param id
Expand Down

0 comments on commit 80fb4de

Please sign in to comment.