feat: return 429 if request queue full

master
Sean McBride 3 years ago
parent 362bf39047
commit 823c46f6f8

@ -43,6 +43,7 @@ global_request_scheduler_initialize(struct global_request_scheduler_config *conf
/** /**
* Adds a sandbox to the request scheduler * Adds a sandbox to the request scheduler
* @param sandbox * @param sandbox
* @returns pointer to sandbox if added. NULL otherwise
*/ */
struct sandbox * struct sandbox *
global_request_scheduler_add(struct sandbox *sandbox) global_request_scheduler_add(struct sandbox *sandbox)

@ -12,7 +12,7 @@ static pthread_mutex_t global_request_scheduler_deque_mutex = PTHREAD_MUTEX_INIT
/** /**
* Pushes a sandbox to the global deque * Pushes a sandbox to the global deque
* @param sandbox_raw * @param sandbox_raw
* @returns pointer to request if added. NULL otherwise * @returns pointer to sandbox if added. NULL otherwise
*/ */
static struct sandbox * static struct sandbox *
global_request_scheduler_deque_add(struct sandbox *sandbox) global_request_scheduler_deque_add(struct sandbox *sandbox)

@ -12,7 +12,7 @@ static struct priority_queue *global_request_scheduler_minheap;
/** /**
* Pushes a sandbox to the global deque * Pushes a sandbox to the global deque
* @param sandbox * @param sandbox
* @returns pointer to request if added. Panics runtime otherwise * @returns pointer to sandbox if added. NULL otherwise
*/ */
static struct sandbox * static struct sandbox *
global_request_scheduler_minheap_add(struct sandbox *sandbox) global_request_scheduler_minheap_add(struct sandbox *sandbox)
@ -22,8 +22,8 @@ global_request_scheduler_minheap_add(struct sandbox *sandbox)
if (unlikely(!listener_thread_is_running())) panic("%s is only callable by the listener thread\n", __func__); if (unlikely(!listener_thread_is_running())) panic("%s is only callable by the listener thread\n", __func__);
int return_code = priority_queue_enqueue(global_request_scheduler_minheap, sandbox); int return_code = priority_queue_enqueue(global_request_scheduler_minheap, sandbox);
/* TODO: Propagate -1 to caller. Issue #91 */
if (return_code == -ENOSPC) panic("Request Queue is full\n"); if (return_code != 0) return NULL;
return sandbox; return sandbox;
} }

@ -189,8 +189,14 @@ listener_thread_main(void *dummy)
&sandbox->client_address); &sandbox->client_address);
} }
/* Add to the Global Sandbox Request Scheduler */ /* If the global request scheduler is full, return a 429 to the client */
global_request_scheduler_add(sandbox); sandbox = global_request_scheduler_add(sandbox);
if (unlikely(sandbox == NULL)) {
client_socket_send_oneshot(sandbox->client_socket_descriptor,
http_header_build(429), http_header_len(429));
client_socket_close(sandbox->client_socket_descriptor,
&sandbox->client_address);
}
} /* while true */ } /* while true */
} /* for loop */ } /* for loop */

Loading…
Cancel
Save