Skip to content

Commit 05275f5

Browse files
committed
fix(ssh): avoid usage of closed connection on web endpoint handler
1 parent 89038fd commit 05275f5

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

ssh/http/handlers.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"strings"
99
"sync"
10+
"time"
1011

1112
"github.com/labstack/echo/v4"
1213
"github.com/shellhub-io/shellhub/pkg/api/internalclient"
@@ -164,15 +165,9 @@ func (h *Handlers) HandleHTTPProxy(c echo.Context) error {
164165
var wg sync.WaitGroup
165166
wg.Add(2)
166167

167-
done := sync.OnceFunc(func() {
168-
// underlying connection closed by done() after copy
169-
defer out.Close()
170-
171-
logger.Trace("close called on in and out connections")
172-
})
168+
starTime := time.Now()
173169

174170
go func() {
175-
defer done()
176171
defer wg.Done()
177172

178173
if _, err := io.Copy(conn, out); err != nil {
@@ -183,7 +178,6 @@ func (h *Handlers) HandleHTTPProxy(c echo.Context) error {
183178
}()
184179

185180
go func() {
186-
defer done()
187181
defer wg.Done()
188182

189183
if _, err := io.Copy(out, conn); err != nil {
@@ -195,7 +189,9 @@ func (h *Handlers) HandleHTTPProxy(c echo.Context) error {
195189

196190
wg.Wait()
197191

198-
logger.Debug("http proxy is done")
192+
logger.WithFields(log.Fields{
193+
"duration": time.Since(starTime).String(),
194+
}).Info("web endpoint request completed")
199195

200196
return nil
201197
}

0 commit comments

Comments
 (0)