Skip to content

Commit

Permalink
add pagelet_server_is_done primitive
Browse files Browse the repository at this point in the history
Summary: In order to fix the hhvm crash from pageletserver error handler flushing output after the output buffer has closed, we need a way to tell if the pagelet thread is done; currently there is no good way to do this from inside the thread itself.

Reviewed By: jano

Differential Revision: D3858448

fbshipit-source-id: 826930f6667b8b3f067e39dd7ae6ed4b0eb5a08a
  • Loading branch information
ngavalas authored and Hhvm Bot committed Sep 14, 2016
1 parent c02b950 commit c1e3800
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hphp/runtime/ext/server/ext_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static struct ServerExtension final : Extension {
HHVM_FE(pagelet_server_task_result);
HHVM_FE(pagelet_server_tasks_started);
HHVM_FE(pagelet_server_flush);
HHVM_FE(pagelet_server_is_done);
HHVM_FE(xbox_send_message);
HHVM_FE(xbox_post_message);
HHVM_FE(xbox_task_start);
Expand Down Expand Up @@ -139,6 +140,16 @@ void HHVM_FUNCTION(pagelet_server_flush) {
}
}

bool HHVM_FUNCTION(pagelet_server_is_done) {
PageletTransport *job =
dynamic_cast<PageletTransport *>(g_context->getTransport());
if (job) {
return job->isDone();
}
// if we aren't in a pagelet thread, this call is meaningless
return true;
}

///////////////////////////////////////////////////////////////////////////////
// xbox

Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/ext/server/ext_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ String HHVM_FUNCTION(pagelet_server_task_result,
int64_t timeout_ms);
int64_t HHVM_FUNCTION(pagelet_server_tasks_started);
void HHVM_FUNCTION(pagelet_server_flush);
bool HHVM_FUNCTION(pagelet_server_is_done);
bool HHVM_FUNCTION(xbox_send_message,
const String& msg,
VRefParam ret,
Expand Down
7 changes: 7 additions & 0 deletions hphp/runtime/ext/server/ext_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function pagelet_server_tasks_started(): int;
<<__HipHopSpecific, __Native>>
function pagelet_server_flush(): void;

/**
* Determine whether or not the pagelet thread we are executing on has finished
* and closed its output buffer.
*/
<<__HipHopSpecific, __Native>>
function pagelet_server_is_done(): bool;

/**
* Sends an xbox message and waits for response. Please read server
* documentation for what an xbox is.
Expand Down

0 comments on commit c1e3800

Please sign in to comment.