From ac0d906d987ee29b989d1dcfa7e039223650a996 Mon Sep 17 00:00:00 2001 From: Giacomo Dematteis Date: Tue, 8 Jul 2025 09:30:02 +0200 Subject: [PATCH 1/2] zephyr platform http: allow larger buf size for large transmissions This be optimized to make the large uploads faster, before any network timeout. --- ports/zephyr/common/memfault_platform_http.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/zephyr/common/memfault_platform_http.c b/ports/zephyr/common/memfault_platform_http.c index 8b7bae915..ece26c648 100644 --- a/ports/zephyr/common/memfault_platform_http.c +++ b/ports/zephyr/common/memfault_platform_http.c @@ -388,7 +388,12 @@ static int prv_send_next_msg(sMemfaultHttpContext *ctx) { memfault_http_start_chunk_post(prv_send_data, &sock, metadata.single_chunk_message_length); while (1) { - uint8_t buf[128]; + // Allow somehow a larger buffer for more efficient transfers +#if defined(CONFIG_MEMFAULT_HTTP_CHUNK_TRANSFER_BUFFER_SIZE) + uint8_t buf[CONFIG_MEMFAULT_HTTP_CHUNK_TRANSFER_BUFFER_SIZE]; +#else + uint8_t buf[1024]; +#endif size_t buf_len = sizeof(buf); eMemfaultPacketizerStatus status = memfault_packetizer_get_next(buf, &buf_len); if (status == kMemfaultPacketizerStatus_NoMoreData) { From 57574f62dd7d7fc41d5414e9d2144e7da6b221a0 Mon Sep 17 00:00:00 2001 From: Giacomo Dematteis Date: Tue, 8 Jul 2025 09:27:18 +0200 Subject: [PATCH 2/2] zephyr platform http: close socket on failed upload --- ports/zephyr/common/memfault_platform_http.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/zephyr/common/memfault_platform_http.c b/ports/zephyr/common/memfault_platform_http.c index ece26c648..0ff168c3e 100644 --- a/ports/zephyr/common/memfault_platform_http.c +++ b/ports/zephyr/common/memfault_platform_http.c @@ -704,9 +704,8 @@ ssize_t memfault_zephyr_port_post_data_return_size(void) { rv = memfault_zephyr_port_http_upload_sdk_data(&ctx); } - if (rv == 0) { - memfault_zephyr_port_http_close_socket(&ctx); - } + // Always close the socket to prevent leaks + memfault_zephyr_port_http_close_socket(&ctx); #if defined(CONFIG_MEMFAULT_METRICS_SYNC_SUCCESS) if (rv == 0) {