staging #74
@@ -2,8 +2,6 @@ package lifecycle
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
portUtil "tunnel_pls/internal/port"
|
portUtil "tunnel_pls/internal/port"
|
||||||
@@ -81,28 +79,23 @@ func (l *lifecycle) SetStatus(status types.SessionStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func closeIfNotNil(c interface{ Close() error }) error {
|
||||||
|
if c != nil {
|
||||||
|
return c.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *lifecycle) Close() error {
|
func (l *lifecycle) Close() error {
|
||||||
var firstErr error
|
var errs []error
|
||||||
tunnelType := l.forwarder.TunnelType()
|
tunnelType := l.forwarder.TunnelType()
|
||||||
|
|
||||||
if err := l.forwarder.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
|
if err := closeIfNotNil(l.channel); err != nil {
|
||||||
firstErr = err
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.channel != nil {
|
if err := closeIfNotNil(l.conn); err != nil {
|
||||||
if err := l.channel.Close(); err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, net.ErrClosed) {
|
errs = append(errs, err)
|
||||||
if firstErr == nil {
|
|
||||||
firstErr = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if l.conn != nil {
|
|
||||||
if err := l.conn.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
|
|
||||||
if firstErr == nil {
|
|
||||||
firstErr = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSlug := l.slug.String()
|
clientSlug := l.slug.String()
|
||||||
@@ -113,12 +106,15 @@ func (l *lifecycle) Close() error {
|
|||||||
l.sessionRegistry.Remove(key)
|
l.sessionRegistry.Remove(key)
|
||||||
|
|
||||||
if tunnelType == types.TunnelTypeTCP {
|
if tunnelType == types.TunnelTypeTCP {
|
||||||
if err := l.PortRegistry().SetStatus(l.forwarder.ForwardedPort(), false); err != nil && firstErr == nil {
|
if err := l.PortRegistry().SetStatus(l.forwarder.ForwardedPort(), false); err != nil {
|
||||||
firstErr = err
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
if err := l.forwarder.Close(); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firstErr
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lifecycle) IsActive() bool {
|
func (l *lifecycle) IsActive() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user