diff --git a/runtime/include/client_socket.h b/runtime/include/client_socket.h index 98f01d5..bab817a 100644 --- a/runtime/include/client_socket.h +++ b/runtime/include/client_socket.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -13,14 +14,22 @@ static inline void -client_socket_close(int client_socket) +client_socket_close(int client_socket, struct sockaddr *client_address) { /* Should never close 0, 1, or 2 */ assert(client_socket != STDIN_FILENO); assert(client_socket != STDOUT_FILENO); assert(client_socket != STDERR_FILENO); - if (unlikely(close(client_socket) < 0)) debuglog("Error closing client socket - %s", strerror(errno)); + + if (unlikely(close(client_socket) < 0)) { + char client_address_text[INET6_ADDRSTRLEN] = {}; + if (unlikely(inet_ntop(AF_INET, &client_address, client_address_text, INET6_ADDRSTRLEN) == NULL)) { + debuglog("Failed to log client_address: %s", strerror(errno)); + } + debuglog("Error closing client socket %d associated with %s - %s", client_socket, client_address_text, + strerror(errno)); + } } diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index 6d3d940..fbefc5f 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -297,7 +297,7 @@ sandbox_close_http(struct sandbox *sandbox) int rc = epoll_ctl(worker_thread_epoll_file_descriptor, EPOLL_CTL_DEL, sandbox->client_socket_descriptor, NULL); if (unlikely(rc < 0)) panic_err(); - client_socket_close(sandbox->client_socket_descriptor); + client_socket_close(sandbox->client_socket_descriptor, &sandbox->client_address); } diff --git a/runtime/src/local_runqueue_list.c b/runtime/src/local_runqueue_list.c index 92b5cc8..00dad65 100644 --- a/runtime/src/local_runqueue_list.c +++ b/runtime/src/local_runqueue_list.c @@ -60,7 +60,7 @@ local_runqueue_list_get_next() return sandbox; err_allocate: client_socket_send(sandbox_request->socket_descriptor, 503); - client_socket_close(sandbox_request->socket_descriptor); + client_socket_close(sandbox_request->socket_descriptor, &sandbox->client_address); free(sandbox_request); err: sandbox = NULL; diff --git a/runtime/src/local_runqueue_minheap.c b/runtime/src/local_runqueue_minheap.c index d93bfc3..215dd9a 100644 --- a/runtime/src/local_runqueue_minheap.c +++ b/runtime/src/local_runqueue_minheap.c @@ -92,7 +92,7 @@ local_runqueue_minheap_get_next() sandbox = sandbox_allocate(sandbox_request); if (!sandbox) { client_socket_send(sandbox_request->socket_descriptor, 503); - client_socket_close(sandbox_request->socket_descriptor); + client_socket_close(sandbox_request->socket_descriptor, &sandbox->client_address); free(sandbox_request); continue; }; @@ -193,7 +193,7 @@ done: return; err_sandbox_allocate: client_socket_send(sandbox_request->socket_descriptor, 503); - client_socket_close(sandbox_request->socket_descriptor); + client_socket_close(sandbox_request->socket_descriptor, &sandbox_request->socket_address); debuglog("local_runqueue_minheap_preempt failed to allocate sandbox\n"); err: goto done; diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index a90bddd..89dbda9 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -10,6 +10,7 @@ #include "http_total.h" #include "local_completion_queue.h" #include "local_runqueue.h" +#include "likely.h" #include "panic.h" #include "runtime.h" #include "sandbox.h" @@ -85,6 +86,20 @@ sandbox_receive_and_parse_client_request(struct sandbox *sandbox) } } + /* Client request is malformed */ + if (recved == 0 && !sandbox->http_request.message_end) { + char client_address_text[INET6_ADDRSTRLEN] = {}; + if (unlikely(inet_ntop(AF_INET, &sandbox->client_address, client_address_text, INET6_ADDRSTRLEN) + == NULL)) { + debuglog("Failed to log client_address: %s", strerror(errno)); + } + + debuglog("Sandbox %lu: recv returned 0 before a complete request was received\n", sandbox->id); + debuglog("Socket: %d. Address: %s\n", fd, client_address_text); + http_request_print(&sandbox->http_request); + goto err; + } + #ifdef LOG_HTTP_PARSER debuglog("Sandbox: %lu http_parser_execute(%p, %p, %p, %zu\n)", sandbox->id, parser, settings, buf, recved); @@ -99,13 +114,6 @@ sandbox_receive_and_parse_client_request(struct sandbox *sandbox) goto err; } - if (recved == 0 && !sandbox->http_request.message_end) { -#ifdef LOG_HTTP_PARSER - debuglog("Sandbox %lu: Received 0, but parsing was incomplete\n", sandbox->id); - http_request_print(&sandbox->http_request); -#endif - goto err; - } sandbox->request_response_data_length += nparsed; } @@ -374,6 +382,8 @@ sandbox_allocate_memory(struct module *module) goto alloc_failed; } + assert(addr != NULL); + /* Set the struct sandbox, HTTP Req/Resp buffer, and the initial Wasm Pages as read/write */ errno = 0; void *addr_rw = mmap(addr, sandbox_size + linear_memory_size, PROT_READ | PROT_WRITE,