diff --git a/runtime/include/http_response.h b/runtime/include/http_response.h index f8b705e..8814077 100644 --- a/runtime/include/http_response.h +++ b/runtime/include/http_response.h @@ -10,6 +10,7 @@ #include "http.h" #define HTTP_RESPONSE_200_OK "HTTP/1.1 200 OK\r\n" +#define HTTP_RESPONSE_504_SERVICE_UNAVAILABLE "HTTP/1.1 504 Service Unavailable\r\n\r\n" #define HTTP_RESPONSE_CONTENT_LENGTH "Content-Length: " #define HTTP_RESPONSE_CONTENT_LENGTH_TERMINATOR "\r\n\r\n" /* content body follows this */ #define HTTP_RESPONSE_CONTENT_TYPE "Content-Type: " diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 8d69580..47c148c 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -7,6 +7,7 @@ #include "global_request_scheduler_deque.h" #include "global_request_scheduler_minheap.h" #include "http_parser_settings.h" +#include "http_response.h" #include "module.h" #include "runtime.h" #include "sandbox_request.h" @@ -115,10 +116,11 @@ listener_thread_main(void *dummy) /* * Reject Requests that exceed system capacity - * TODO: Enhance to gracefully return HTTP status code 503 Service Unavailable */ if (runtime_admitted + admissions_estimate >= runtime_worker_threads_count) { - debuglog("Would have rejected!"); + send(socket_descriptor, HTTP_RESPONSE_504_SERVICE_UNAVAILABLE, + strlen(HTTP_RESPONSE_504_SERVICE_UNAVAILABLE), 0); + goto done; } /* Allocate a Sandbox Request */ @@ -137,6 +139,7 @@ listener_thread_main(void *dummy) } } +done: free(epoll_events); return NULL; }