Skip to content

Commit

Permalink
Close connections on error
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Jun 24, 2022
1 parent 17a419e commit efad0db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (c *serverCmd) handleTunnelRequest(mux *vhost.TLSMuxer, conn net.Conn) erro
sni := msg.GetTls().GetSni()
s := c.sessionRegistry.find(sni)
if s != nil {
defer conn.Close()
defer sess.Close()
log.Trace().Msgf("Session already exists in the registry for %s", sni)
err = c.returnResponse(initialConn, messages.TunnelStatus_ALREADY_EXISTS)
if err != nil {
Expand All @@ -127,6 +129,8 @@ func (c *serverCmd) handleTunnelRequest(mux *vhost.TLSMuxer, conn net.Conn) erro
if muxListener != nil {
muxListener.Close()
}
defer conn.Close()
defer sess.Close()
if strings.Contains(strings.ToLower(err.Error()), "already bound") {
err = c.returnResponse(initialConn, messages.TunnelStatus_ALREADY_EXISTS)
if err != nil {
Expand Down Expand Up @@ -302,6 +306,10 @@ func (c *serverCmd) run() error {
r.GET("/tunnels", func(c1 *gin.Context) {
c1.JSON(200, c.sessionRegistry.sessions)
})
r.DELETE("/tunnels/:sni", func(c1 *gin.Context) {
c.sessionRegistry.delete(c1.Param("sni"))
c1.JSON(200, c.sessionRegistry.sessions)
})
log.Info().Msgf("admin server listening on %s", c.adminAddr)
err := r.Run(c.adminAddr)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (c *tunnelClient) StartTlsTunnel(sni string, remoteAddress string) error {
log.Trace().Msgf("Failed to connect to tunnel: %v", err)
return err
}
session, err := yamux.Client(conn, nil)
cfg := yamux.DefaultConfig()
session, err := yamux.Client(conn, cfg)
if err != nil {
log.Trace().Msgf("Failed to create yamux session: %v", err)
return err
Expand Down

0 comments on commit efad0db

Please sign in to comment.