fix: ssh not proxied when workspace restarts

This commit is contained in:
2024-11-17 18:30:07 +00:00
parent 45bfbe093a
commit fb5e708fd8
3 changed files with 57 additions and 20 deletions

View File

@@ -6,17 +6,24 @@ type SSHProxy struct {
internalPorts map[int]int
connections map[int]*proxyConnection
closedConnections chan *proxyConnection
}
func New() *SSHProxy {
return &SSHProxy{
internalPorts: map[int]int{},
connections: map[int]*proxyConnection{},
p := &SSHProxy{
internalPorts: map[int]int{},
connections: map[int]*proxyConnection{},
closedConnections: make(chan *proxyConnection),
}
go p.handleClosedConnections()
return p
}
func (p *SSHProxy) NewProxyEntryTo(toPort int) error {
c, err := newProxyConnection(toPort)
c, err := newProxyConnection(toPort, p.closedConnections)
if err != nil {
return err
}
@@ -35,3 +42,10 @@ func (p *SSHProxy) FindExternalPort(internalPort int) int {
}
return -1
}
func (p *SSHProxy) handleClosedConnections() {
for c := range p.closedConnections {
delete(p.internalPorts, c.internalPort)
delete(p.connections, c.internalPort)
}
}