From 7005dd14672ecbe18f845a4cdf1d58dd891a9b28 Mon Sep 17 00:00:00 2001 From: xiaosuGW Date: Wed, 13 Oct 2021 16:35:26 -0400 Subject: [PATCH] A simple solution to fix bug: sledge reply 200 even though the function code return a negative value --- runtime/src/current_sandbox.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index d7a74f1..f398660 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -108,11 +108,19 @@ current_sandbox_start(void) int32_t argument_count = module_get_argument_count(current_module); current_sandbox_enable_preemption(sandbox); sandbox->return_value = module_main(current_module, argument_count, sandbox->arguments_offset); + if (sandbox->return_value < 0) { + printf("module returns error code %d\n", sandbox->return_value); + } current_sandbox_disable_preemption(sandbox); sandbox->completion_timestamp = __getcycles(); - - if (next_module != NULL) { + /* Function code execution failed, terminate the request */ + if (sandbox->return_value < 0) { + /* TODO: Simply goto err is not perfect because not print out the response meesage of the function code. + * Should return 400 and the err message in the http response body. + */ + goto err; + } else if (next_module != NULL) { /* Generate a new request, copy the current sandbox's output to the next request's buffer, and put it to the global queue */ ssize_t output_length = sandbox->request_response_data_length - sandbox->request_length; char * pre_func_output = (char *)malloc(output_length);