Skip to content

Commit 75c9dc6

Browse files
author
gophergogo
committed
Disable body timeout for client-mode HTTP codec (#212)
Client connections carry SSE responses whose body is an open-ended stream of events — quiet periods between events are expected and valid. The 60s body timeout was firing on these, and the state machine's executeTransition() then crashed on a still-live stream. Set body_timeout to 0 (disabled) for client mode; keep 60s on server mode where request bodies are expected to complete promptly.
1 parent 12b8cf3 commit 75c9dc6

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/filter/http_codec_filter.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,16 @@ HttpCodecFilter::HttpCodecFilter(MessageCallbacks& callbacks,
105105
// Initialize message encoder
106106
message_encoder_ = std::make_unique<MessageEncoderImpl>(*this);
107107

108-
// Initialize HTTP codec state machine
108+
// Initialize HTTP codec state machine.
109+
// Client-side body_timeout is disabled (0 == no timeout): an SSE response
110+
// body is an open-ended stream that may stay silent between events for
111+
// longer than a request/response body timeout would tolerate. Servers keep
112+
// the bounded timeout — request bodies are expected to complete promptly.
109113
HttpCodecStateMachineConfig config;
110-
config.is_server = is_server_; // Set mode
114+
config.is_server = is_server_;
111115
config.header_timeout = std::chrono::milliseconds(30000);
112-
config.body_timeout = std::chrono::milliseconds(60000);
116+
config.body_timeout = is_server_ ? std::chrono::milliseconds(60000)
117+
: std::chrono::milliseconds(0);
113118
config.idle_timeout = std::chrono::milliseconds(120000);
114119
config.enable_keep_alive = true;
115120
config.state_change_callback =
@@ -156,12 +161,15 @@ HttpCodecFilter::HttpCodecFilter(const filter::FilterCreationContext& context,
156161
// Initialize message encoder
157162
message_encoder_ = std::make_unique<MessageEncoderImpl>(*this);
158163

159-
// Initialize HTTP codec state machine with same defaults for now
164+
// Initialize HTTP codec state machine.
165+
// Client-side body_timeout is disabled (0) for the same reason as the
166+
// other constructor: SSE streams may sit idle between server-pushed events.
160167
// TODO: Extract timeout values from config parameter
161168
HttpCodecStateMachineConfig sm_config;
162169
sm_config.is_server = is_server_;
163170
sm_config.header_timeout = std::chrono::milliseconds(30000);
164-
sm_config.body_timeout = std::chrono::milliseconds(60000);
171+
sm_config.body_timeout = is_server_ ? std::chrono::milliseconds(60000)
172+
: std::chrono::milliseconds(0);
165173
sm_config.idle_timeout = std::chrono::milliseconds(120000);
166174
sm_config.enable_keep_alive = true;
167175
sm_config.state_change_callback =

0 commit comments

Comments
 (0)