fix: reduce server timeout settings and add deadline for UDP connection reads

This commit is contained in:
Eric Zhou
2025-09-03 09:36:24 +08:00
parent e0cc6ecad5
commit 7b4d3e7440
2 changed files with 7 additions and 5 deletions

View File

@@ -45,9 +45,9 @@ func (app *App) httpSvr() {
server := &http.Server{
Addr: app.cfg.ListenAddr(),
Handler: mux,
ReadTimeout: 180 * time.Second,
WriteTimeout: 180 * time.Second,
IdleTimeout: 180 * time.Second,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 60 * time.Second,
}
app.svr = server
@@ -66,8 +66,9 @@ func NewApp(c *global.Config, sig chan os.Signal) *App {
},
},
upGrader: &websocket.Upgrader{
ReadBufferSize: bufferSize,
WriteBufferSize: bufferSize,
HandshakeTimeout: 2 * time.Second,
ReadBufferSize: bufferSize,
WriteBufferSize: bufferSize,
CheckOrigin: func(r *http.Request) bool {
// Allow all connections by default
return true

View File

@@ -212,6 +212,7 @@ func (app *App) vlessUDP(_ context.Context, sv *schema.ProtoVLESS, ws *websocket
buf := app.bufferPool.Get().([]byte)
defer app.bufferPool.Put(buf)
conn.SetDeadline(time.Now().Add(2 * time.Second))
n, err := conn.Read(buf)
if err != nil {
logger.Error("Error reading from UDP connection:", "err", err)