Skip to content

Commit

Permalink
Add a timeout to postBlockingTask() (youtube#554)
Browse files Browse the repository at this point in the history
b/234788479
  • Loading branch information
sherryzy authored Jun 7, 2023
1 parent 1debc23 commit 8024174
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion base/single_thread_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "base/debug/stack_trace.h"
#include "base/single_thread_task_runner.h"
#include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h"
Expand Down Expand Up @@ -47,7 +48,17 @@ void SingleThreadTaskRunner::PostBlockingTask(const base::Location& from_here,

if (task_may_run) {
// Wait for the task to complete before proceeding.
task_finished.Wait();
do {
if (task_finished.TimedWait(base::TimeDelta::FromMilliseconds(1000))) {
break;
}
#if !defined(COBALT_BUILD_TYPE_GOLD)
base::debug::StackTrace trace;
trace.PrintWithPrefix("[task runner deadlock]");
#endif // !defined(COBALT_BUILD_TYPE_GOLD)
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
base::RunLoop().RunUntilIdle();
} while (true);
}
}
#endif
Expand Down

0 comments on commit 8024174

Please sign in to comment.