zchuango commented on code in PR #3409:
URL: https://github.com/apache/brpc/pull/3409#discussion_r3735812573
##########
src/brpc/controller.cpp:
##########
@@ -174,6 +175,80 @@ class IgnoreAllRead : public ProgressiveReader {
void OnEndOfMessage(const butil::Status&) {}
};
+class ProgressiveTimeoutReader : public ProgressiveReader {
+public:
+ explicit ProgressiveTimeoutReader(SocketId id, int32_t read_timeout_ms,
ProgressiveReader* reader):
+ _socket_id(id),
+ _read_timeout_ms(read_timeout_ms),
+ _reader(reader),
+ _timeout_id(0),
+ _is_read_timeout(false) {
+ AddIdleReadTimeoutMonitor();
+ }
+
+ ~ProgressiveTimeoutReader() {
+ if(_timeout_id > 0) {
+ bthread_timer_del(_timeout_id);
+ }
+ }
+
+ butil::Status OnReadOnePart(const void* data, size_t length) {
+ return _reader->OnReadOnePart(data, length);
+ }
+
+ void OnEndOfMessage(const butil::Status& status) {
+ if (_is_read_timeout) {
+ _reader->OnEndOfMessage(butil::Status(EPROGREADTIMEOUT, "The
progressive read timeout"));
+ } else {
+ _reader->OnEndOfMessage(status);
+ }
+ if(_timeout_id > 0) {
+ bthread_timer_del(_timeout_id);
+ _timeout_id = 0;
+ }
+ }
+
+private:
+ static void HandleIdleProgressiveReader(void* arg) {
+ if(arg == nullptr){
+ LOG(ERROR) << "Controller::HandleIdleProgressiveReader arg is
null.";
+ return;
+ }
+ ProgressiveTimeoutReader* reader =
static_cast<ProgressiveTimeoutReader*>(arg);
+ SocketUniquePtr s;
+ if (Socket::Address(reader->_socket_id, &s) != 0) {
+ LOG(ERROR) << "not found the socket id : " << reader->_socket_id;
+ return;
+ }
+ auto log_idle = FLAGS_log_idle_progressive_read_close;
+ reader->_is_read_timeout = true;
+ LOG_IF(INFO, log_idle) << "progressive read timeout socket id : " <<
reader->_socket_id
+ << " progressive read timeout us : " << reader->_read_timeout_ms;
Review Comment:
Fixed. HttpContext::_socket_id is now initialized to INVALID_SOCKET_ID, so
an unset socket ID cannot be mistaken for a valid one.
##########
src/brpc/controller.cpp:
##########
@@ -174,6 +175,80 @@ class IgnoreAllRead : public ProgressiveReader {
void OnEndOfMessage(const butil::Status&) {}
};
+class ProgressiveTimeoutReader : public ProgressiveReader {
+public:
+ explicit ProgressiveTimeoutReader(SocketId id, int32_t read_timeout_ms,
ProgressiveReader* reader):
+ _socket_id(id),
+ _read_timeout_ms(read_timeout_ms),
+ _reader(reader),
+ _timeout_id(0),
+ _is_read_timeout(false) {
+ AddIdleReadTimeoutMonitor();
+ }
+
+ ~ProgressiveTimeoutReader() {
+ if(_timeout_id > 0) {
+ bthread_timer_del(_timeout_id);
+ }
+ }
+
+ butil::Status OnReadOnePart(const void* data, size_t length) {
+ return _reader->OnReadOnePart(data, length);
+ }
+
+ void OnEndOfMessage(const butil::Status& status) {
+ if (_is_read_timeout) {
+ _reader->OnEndOfMessage(butil::Status(EPROGREADTIMEOUT, "The
progressive read timeout"));
+ } else {
+ _reader->OnEndOfMessage(status);
+ }
+ if(_timeout_id > 0) {
+ bthread_timer_del(_timeout_id);
+ _timeout_id = 0;
+ }
+ }
+
+private:
+ static void HandleIdleProgressiveReader(void* arg) {
+ if(arg == nullptr){
+ LOG(ERROR) << "Controller::HandleIdleProgressiveReader arg is
null.";
+ return;
+ }
+ ProgressiveTimeoutReader* reader =
static_cast<ProgressiveTimeoutReader*>(arg);
+ SocketUniquePtr s;
+ if (Socket::Address(reader->_socket_id, &s) != 0) {
+ LOG(ERROR) << "not found the socket id : " << reader->_socket_id;
+ return;
+ }
+ auto log_idle = FLAGS_log_idle_progressive_read_close;
+ reader->_is_read_timeout = true;
+ LOG_IF(INFO, log_idle) << "progressive read timeout socket id : " <<
reader->_socket_id
+ << " progressive read timeout us : " << reader->_read_timeout_ms;
Review Comment:
Fixed. HttpContext::_socket_id is now initialized to INVALID_SOCKET_ID, so
an unset socket ID cannot be mistaken for a valid one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]