Skip to content

Commit

Permalink
refactor buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lombardi committed Dec 31, 2024
1 parent f8bc6e3 commit b509fd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/abstractions/shell/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,37 @@ func (g *shellGroup) ShellConnect(ctx echo.Context) error {
// TODO: confirm disconnects happen when python client exits
defer log.Println("disconnected")

// Create a context that will be canceled when the client disconnects
clientCtx, clientCancel := context.WithCancel(ctx.Request().Context())
defer clientCancel()

var wg sync.WaitGroup
wg.Add(2)

// Copy from client -> container
go func() {
defer wg.Done()
buf := make([]byte, 32*1024) // 32KB buffer
io.CopyBuffer(containerConn, conn, buf)
buf := make([]byte, shellProxyBufferSizeKb)
select {
case <-clientCtx.Done():
log.Println("client disconnected")
return
default:
io.CopyBuffer(containerConn, conn, buf)
}
}()

// Copy from container -> client
go func() {
defer wg.Done()
buf := make([]byte, 32*1024) // 32KB buffer
io.CopyBuffer(conn, containerConn, buf)
buf := make([]byte, shellProxyBufferSizeKb)
select {
case <-clientCtx.Done():
log.Println("client disconnected")
return
default:
io.CopyBuffer(conn, containerConn, buf)
}
}()

wg.Wait()
Expand Down
1 change: 1 addition & 0 deletions pkg/abstractions/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
const (
shellRoutePrefix string = "/shell"
shellContainerPrefix string = "shell"
shellProxyBufferSizeKb int = 32 * 1024
defaultContainerCpu int64 = 100
defaultContainerMemory int64 = 128
containerDialTimeoutDurationS time.Duration = 300 * time.Second
Expand Down

0 comments on commit b509fd7

Please sign in to comment.