Skip to content

Commit ce49cd8

Browse files
committed
disable stream timeout context
1 parent fce7ce7 commit ce49cd8

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

server/torr/stream.go

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package torr
22

33
import (
4-
"context"
4+
// "context"
55
"encoding/hex"
66
"errors"
77
"fmt"
@@ -23,20 +23,20 @@ import (
2323
// Add atomic counter for concurrent streams
2424
var activeStreams int32
2525

26-
type contextResponseWriter struct {
27-
http.ResponseWriter
28-
ctx context.Context
29-
}
26+
// type contextResponseWriter struct {
27+
// http.ResponseWriter
28+
// ctx context.Context
29+
// }
3030

31-
func (w *contextResponseWriter) Write(p []byte) (n int, err error) {
32-
// Check context before each write
33-
select {
34-
case <-w.ctx.Done():
35-
return 0, w.ctx.Err()
36-
default:
37-
return w.ResponseWriter.Write(p)
38-
}
39-
}
31+
// func (w *contextResponseWriter) Write(p []byte) (n int, err error) {
32+
// // Check context before each write
33+
// select {
34+
// case <-w.ctx.Done():
35+
// return 0, w.ctx.Err()
36+
// default:
37+
// return w.ResponseWriter.Write(p)
38+
// }
39+
// }
4040

4141
func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter) error {
4242
// Increment active streams counter
@@ -136,21 +136,23 @@ func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter
136136
if req.Header.Get("Range") != "" {
137137
resp.Header().Set("Accept-Ranges", "bytes")
138138
}
139-
// Create a context with timeout if configured
140-
ctx := req.Context()
141-
if streamTimeout > 0 {
142-
var cancel context.CancelFunc
143-
ctx, cancel = context.WithTimeout(ctx, time.Duration(streamTimeout)*time.Second)
144-
defer cancel()
145-
}
146-
// Update request with new context
147-
req = req.WithContext(ctx)
148-
// Handle client disconnections better
149-
wrappedResp := &contextResponseWriter{
150-
ResponseWriter: resp,
151-
ctx: ctx,
152-
}
153-
http.ServeContent(wrappedResp, req, file.Path(), time.Unix(t.Timestamp, 0), reader)
139+
// // Create a context with timeout if configured
140+
// ctx := req.Context()
141+
// if streamTimeout > 0 {
142+
// var cancel context.CancelFunc
143+
// ctx, cancel = context.WithTimeout(ctx, time.Duration(streamTimeout)*time.Second)
144+
// defer cancel()
145+
// }
146+
// // Update request with new context
147+
// req = req.WithContext(ctx)
148+
// // Handle client disconnections better
149+
// wrappedResp := &contextResponseWriter{
150+
// ResponseWriter: resp,
151+
// ctx: ctx,
152+
// }
153+
// http.ServeContent(wrappedResp, req, file.Path(), time.Unix(t.Timestamp, 0), reader)
154+
155+
http.ServeContent(resp, req, file.Path(), time.Unix(t.Timestamp, 0), reader)
154156

155157
if sets.BTsets.EnableDebug {
156158
if clerr != nil {

0 commit comments

Comments
 (0)