mirror of
https://github.com/unchainese/unchain.git
synced 2025-12-24 12:38:02 +08:00
fix: reduce server timeout settings and add deadline for UDP connection reads
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user