Skip to content

Commit

Permalink
Cancel dial on source connection close
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Dec 19, 2022
1 parent 5fd7e3f commit 922bb13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .web/docs/guide/lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ config:
enabled: true
routes:
- host: abc.example.com
backend: 10.0.0.3:25566
- host: '*.minecraft.com'
backend: 10.0.0.2:25567
backend: 10.0.0.3:25568
- host: '*.example.com'
backend: 10.0.0.1:25567
- host: [ example.com, localhost ]
backend: [ 10.0.0.1:25568 ]
backend: [ 10.0.0.2:25566 ]
```
Expand Down
11 changes: 9 additions & 2 deletions pkg/edition/java/proxy/session_handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"bytes"
"context"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -259,9 +260,15 @@ func (h *handshakeSessionHandler) forwardLite(handshake *packet.Handshake, pc *p
log = log.WithValues("backend", backendAddr)

timeout := time.Duration(h.config().ConnectionTimeout) * time.Millisecond
dst, err := net.DialTimeout(src.RemoteAddr().Network(), backendAddr, timeout)
ctx, cancel := context.WithTimeout(h.conn.Context(), timeout)
defer cancel()

var dialer net.Dialer
dst, err := dialer.DialContext(ctx, src.RemoteAddr().Network(), backendAddr)
if err != nil {
log.Info("failed to connect to backend", "error", err.Error())
if ctx.Err() == nil {
log.Info("failed to connect to backend", "error", err.Error())
}
return
}
defer func() { _ = dst.Close() }()
Expand Down

0 comments on commit 922bb13

Please sign in to comment.