forked from mtusi2026/mtusi2026lab7
fix(operations): preserve response processing deadlines and await routed API readiness
This commit is contained in:
@@ -365,6 +365,7 @@ type drainingRequestBody struct {
|
||||
mu sync.Mutex
|
||||
once sync.Once
|
||||
deadline func()
|
||||
reset func()
|
||||
}
|
||||
|
||||
func (b *drainingRequestBody) Read(data []byte) (int, error) {
|
||||
@@ -376,6 +377,7 @@ func (b *drainingRequestBody) Read(data []byte) (int, error) {
|
||||
func (b *drainingRequestBody) Close() error {
|
||||
b.once.Do(func() {
|
||||
b.deadline()
|
||||
defer b.reset()
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
// Drain within a short deadline after an early response so closing TLS does
|
||||
@@ -390,9 +392,12 @@ func serveLoopbackProxy(c Config, proxy *httputil.ReverseProxy, w http.ResponseW
|
||||
if c.Role == "api" && r.Body != nil && r.Body != http.NoBody {
|
||||
controller := http.NewResponseController(w)
|
||||
_ = controller.EnableFullDuplex()
|
||||
_ = controller.SetReadDeadline(time.Now().Add(25 * time.Second))
|
||||
receiveDeadline := time.Now().Add(25 * time.Second)
|
||||
_ = controller.SetReadDeadline(receiveDeadline)
|
||||
body := &drainingRequestBody{ReadCloser: r.Body, deadline: func() {
|
||||
_ = controller.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
}, reset: func() {
|
||||
_ = controller.SetReadDeadline(receiveDeadline)
|
||||
}}
|
||||
r.Body = body
|
||||
defer body.Close()
|
||||
|
||||
Reference in New Issue
Block a user