Skip to content

Commit 8f5089e

Browse files
committed
FIX | bug in http2
1 parent 9d6a619 commit 8f5089e

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/http/ManapiHttp2.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ int http_v2_send_frame (manapi::net::http::http_v2_t *ctx, int frame_type, uint
179179
true, manapi::ev::WRITE);
180180
manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "http2: wait write event");
181181
}
182+
// else {
183+
// manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "http2: blocked flags&HTTP2_CTX_FLAG_BLOCK_WRITE=%d "
184+
// "is_writable(conn)=%d", ctx->flags & manapi::net::http::HTTP2_CTX_FLAG_BLOCK_WRITE, ctx->worker->is_writable(ctx->conn));
185+
// }
182186

183187
return manapi::ERR_OK;
184188
}
@@ -701,20 +705,35 @@ int manapi::net::http::http_v2_on_write(http_v2_t *ctx) MANAPIHTTP_NOEXCEPT {
701705
ctx->flags ^= HTTP2_CTX_FLAG_BLOCK_WRITE;
702706

703707
bool no_one = true;
704-
for (const auto &priority : *ctx->priorities) {
708+
// !!! IN PRIORITY LOOP WE MUST KNOW THAT THE PREVIUS PRIORITY CANT BE CHANGED !!!
709+
auto prev_priority = ctx->priorities->end();
710+
for (auto priority = ctx->priorities->begin(); priority != ctx->priorities->end(); ) {
705711
//auto &conn = (*priority.second);
706-
auto const data = priority.second->as<http_v2_stream_t>();
712+
auto const data = priority->second->as<http_v2_stream_t>();
707713
if (ctx->flags & HTTP2_CTX_FLAG_BLOCK_WRITE) {
708714
break;
709715
}
710716

711-
auto rhs = http_v2_stream_on_write(priority.second, data);
717+
auto rhs = http_v2_stream_on_write(priority->second, data);
712718

713719
if (rhs)
714720
no_one = false;
715721

716722
manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "http2: write event received sid=%u s_write_window=%d processed=%d",
717723
data->id, ctx->write_window, rhs);
724+
725+
if (ctx->priorities->empty()) {
726+
break;
727+
}
728+
729+
auto next_prev_priority = prev_priority != ctx->priorities->end() ? std::next(prev_priority) : ctx->priorities->begin();
730+
if (next_prev_priority == priority) {
731+
prev_priority = priority;
732+
++priority;
733+
}
734+
else {
735+
priority = next_prev_priority;
736+
}
718737
}
719738

720739
if (no_one)
@@ -2508,7 +2527,8 @@ ssize_t manapi::net::http::http_v2_write(const worker::shared_conn &conn, ev::bu
25082527

25092528
res += size;
25102529

2511-
if (!s->ctx->http_v2_worker->is_writable(conn))
2530+
if (!s->ctx->http_v2_worker->is_writable(conn)
2531+
|| (s->ctx->flags & HTTP2_CTX_FLAG_BLOCK_WRITE))
25122532
break;
25132533

25142534
if (lencut) {
@@ -2522,6 +2542,16 @@ ssize_t manapi::net::http::http_v2_write(const worker::shared_conn &conn, ev::bu
25222542
nbuff -= pnbuff;
25232543
}
25242544

2545+
auto left = static_cast<int>(copy - res);
2546+
if (left) {
2547+
s->ctx->write_window += left;
2548+
s->write_window += left;
2549+
if (s->write_window == left) {
2550+
if (http_v2_update_priority(s->ctx, conn, s)) {
2551+
return -1;
2552+
}
2553+
}
2554+
}
25252555
s->transfered_k += static_cast<int>(res);
25262556

25272557
if (finish && res == copy) {

src/include/http/ManapiHttp2.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,18 @@ namespace manapi::net::http {
119119
};
120120

121121
int http_v2_on_close (http_v2_t *ctx) MANAPIHTTP_NOEXCEPT;
122+
122123
int http_v2_on_close_stream (http_v2_t *ctx, uint32_t id) MANAPIHTTP_NOEXCEPT;
124+
123125
int http_v2_on_write (http_v2_t *ctx) MANAPIHTTP_NOEXCEPT;
126+
124127
int http_v2_on_read_stream (const worker::shared_conn &conn) MANAPIHTTP_NOEXCEPT;
128+
125129
int http_v2_work (http_v2_t *ctx, http::config *config, const char **nbuffer, ssize_t *nsize) MANAPIHTTP_NOEXCEPT;
130+
126131
ssize_t http_v2_write (const worker::shared_conn &conn, ev::buff_t *buff, uint32_t nbuff, bool finish) MANAPIHTTP_NOEXCEPT;
132+
127133
int http_v2_rst_stream (const worker::shared_conn &s, int errcode) MANAPIHTTP_NOEXCEPT;
134+
128135
manapi::future<int> http_v2_response (worker::base *worker, const worker::shared_conn &connection, int status, std::map<std::string, std::string, std::less<>> headers, bool finish);
129136
}

0 commit comments

Comments
 (0)