Skip to content

Commit

Permalink
Try smaller buffer size with larger timeouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecarter94 committed Nov 26, 2024
1 parent d858adc commit cf869ce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deploy/tasks/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ spec:
- name: BYTE_BUFFER_SIZE
description: The byte buffer size to use for the domain proxy.
type: string
default: 10485760
default: 1024
- name: PROXY_TARGET_WHITELIST
description: Comma separated whitelist of target hosts for the domain proxy.
type: string
Expand Down
19 changes: 6 additions & 13 deletions domain-proxy/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (

const (
ByteBufferSizeKey = "BYTE_BUFFER_SIZE"
DefaultByteBufferSize = 10485760
DefaultByteBufferSize = 1024
DomainSocketKey = "DOMAIN_SOCKET"
DefaultDomainSocket = "/tmp/domain-socket.sock"
ConnectionTimeoutKey = "CONNECTION_TIMEOUT"
DefaultConnectionTimeout = 1000 * time.Millisecond
IdleTimeoutKey = "IDLE_TIMEOUT"
DefaultIdleTimeout = 1000 * time.Millisecond
DefaultIdleTimeout = 30000 * time.Millisecond
)

var Logger *log.Logger
Expand All @@ -41,27 +41,20 @@ func BiDirectionalTransfer(leftConn, rightConn net.Conn, byteBufferSize int, idl
<-done
}

func Transfer(targetConn, sourceConn net.Conn, done chan struct{}, bufferSize int, idleTimeout time.Duration) {
func Transfer(sourceConn, targetConn net.Conn, done chan struct{}, bufferSize int, idleTimeout time.Duration) {
defer func() {
done <- struct{}{}
}()
buf := make([]byte, bufferSize)
for {
n, err := sourceConn.Read(buf)
n, err := io.CopyBuffer(sourceConn, targetConn, buf)
if err != nil {
handleConnectionError(err)
return
} else if n > 0 {
Logger.Printf("%d bytes read", n)
sourceConn.SetReadDeadline(time.Now().Add(idleTimeout))

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.
n, err = targetConn.Write(buf[:n])
if err != nil {
handleConnectionError(err)
return
} else if n > 0 {
Logger.Printf("%d bytes written", n)
targetConn.SetWriteDeadline(time.Now().Add(idleTimeout))
}
targetConn.SetWriteDeadline(time.Now().Add(idleTimeout))

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.
Logger.Printf("%d bytes transferred", n)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion domain-proxy/domain_proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (dpc *DomainProxyClient) Stop() {
if err := dpc.listener.Close(); err != nil {
Logger.Printf("Error closing listener: %v", err)
}
dpc.executor.Wait()
//dpc.executor.Wait()
}

func GetServerHttpPort() int {
Expand Down
2 changes: 1 addition & 1 deletion domain-proxy/domain_proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (dps *DomainProxyServer) Stop() {
if err := dps.listener.Close(); err != nil {
Logger.Printf("Error closing listener: %v", err)
}
dps.executor.Wait()
//dps.executor.Wait()
if _, err := os.Stat(dps.domainSocket); err == nil {
if err := os.Remove(dps.domainSocket); err != nil {
Logger.Printf("Error deleting domain socket: %v", err)
Expand Down

0 comments on commit cf869ce

Please sign in to comment.