Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drogon_http_async_writer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void DrogonHttpAsyncWriterImpl::PartialReplyBegin(std::function<void()> actualWo
this->responsePtr = drogon::HttpResponse::newAsyncStreamResponse(
[this, actualWorkloadCallback = std::move(actualWorkloadCallback)](drogon::ResponseStreamPtr stream) {
this->stream = std::move(stream);
this->pool.Schedule([actualWorkloadCallback = std::move(actualWorkloadCallback)] {
this->pool.Schedule([&actualWorkloadCallback] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what ensures us that the lifetime of actualWorkloadCallback will be greater than Scheduler task lifetime?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPDLOG_DEBUG("DrogonHttpAsyncWriterImpl::PartialReplyBegin::Schedule begin");
try {
actualWorkloadCallback(); // run actual workload (mediapipe executor inferStream) which uses PartialReply
Expand Down
4 changes: 3 additions & 1 deletion src/http_rest_api_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ Status HttpRestApiHandler::processV3(const std::string_view uri, const HttpReque
serverReaderWriter->OverwriteResponseHeader("Content-Type", "text/event-stream");
serverReaderWriter->OverwriteResponseHeader("Cache-Control", "no-cache");
serverReaderWriter->OverwriteResponseHeader("Connection", "keep-alive");
serverReaderWriter->PartialReplyBegin([executor = std::move(executor), serverReaderWriter, request = std::move(request)] {
serverReaderWriter->PartialReplyBegin([executor = std::move(executor), serverReaderWriter, request = std::move(request)]() mutable {
ExecutionContext executionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::V3Stream};
auto status = executor->inferStream(request, *serverReaderWriter, executionContext);
if (!status.ok()) {
Expand All @@ -729,6 +729,8 @@ Status HttpRestApiHandler::processV3(const std::string_view uri, const HttpReque
serverReaderWriter->PartialReplyWithStatus(buffer.GetString(), HTTPStatusCode::BAD_REQUEST);
}
serverReaderWriter->PartialReplyEnd();
// Release executor resources after the work is done - for example CB pipeline object
executor.reset()
});
return StatusCode::PARTIAL_END;
}
Expand Down