Bug #5752
closedWt::Http::Client emits done() signal twice with chunked response with 1 chunk only
0%
Description
HTTP servers usually use chunked responses for long responses. However the response may be small enough (especially during tests) and may consist of 1 chunk only.
Wt::Http::Client uses complete() function to execute stop() function (which changes aborted_ to true) and emits done() signal.
In case of chunked response the complete() function is executed from addBodyText() function when the state is ChunkState::Complete.
To avoid the done() signal beeing emitted twice there is "if (!aborted_)" after executing addBodyText() function inside handleReadContent() function.
However the addBodyText() function is also executed in handleReadHeaders() function for the first time. It is possible that this function will read the whole chunk until EOF and emit the done() signal and the following execution of handleReadContent() will read EOF and execute the complete() function for the second time which will result in emitting the done() signal for the second time.
To fix the error I added "if (!aborted_)" in handleReadHeaders() function after addBodyText() and before startTimer() and reading content.
Two done() signals for the single request violates counter in Wt::WApplication::instance()deferRendering() and Wt::WApplication::instance()>resumeRendering() function which are needed to block the current thread of execution correctly. I tried to store the last response.body() to ignore the second signal when the body is the same as last time. But in case of two requests is it possible to have the response for the first request, than for the second request, than for the first again and for the second again. So my method of ignoring signals was wrong. If I executed Wt::WApplication::instance()->resumeRendering() for each signal it resulted in negative counter.
Please, fix the error in the master branch.
Updated by Roel Standaert over 7 years ago
- Status changed from New to Implemented @Emweb
Updated by Roel Standaert over 7 years ago
- Status changed from Implemented @Emweb to Resolved
Updated by Roel Standaert over 7 years ago
- Status changed from Resolved to Closed