Skip to content

Commit 0775eb6

Browse files
authored
Use git apply patch to fix uWebsockets crash, previously fixed by python script in #344 (#507)
Previously we downloaded a tarball release of uWebSockets and then patched the code to fix a crash issue. The patch was executed by a custom python script which somewhat blindly overwrote at set of line numbers in the file. See PR #344 Git apply patch wasn't used because it requires a initialized git repo to work. Cloning the the uWebsockets repo with history and then checking out to an older commit would explode the disk usage, causing parition exhaustion issues on Windows, so we were forced to use the non-git-initialized tarball. Thankfully I found a way to fetch a repo at a specific commit, removing the overhead of cloning all of the history. This change updates the cmake download step for uWebSockets to fetch the commit instead of downloading a tarball. With a git initialized repo we can our change with a far safer git apply patch instead of our custom python script, akin to what was done for boringSSL in PR #485
1 parent b5d3b1e commit 0775eb6

File tree

5 files changed

+68
-158
lines changed

5 files changed

+68
-158
lines changed

cmake/external/boringssl.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ endif()
2121
set(patch_file
2222
${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/boringssl/0001-disable-C4255-converting-empty-params-to-void.patch)
2323

24-
set(commit_tag 83da28a68f32023fd3b95a8ae94991a07b1f6c62)
24+
set(boringssl_commit_tag 83da28a68f32023fd3b95a8ae94991a07b1f6c62)
2525

2626
ExternalProject_Add(
2727
boringssl
2828

2929
DOWNLOAD_COMMAND
3030
COMMAND git init boringssl
31-
COMMAND cd boringssl && git fetch --depth=1 https://github.com/google/boringssl ${commit_tag} && git reset --hard FETCH_HEAD
31+
COMMAND cd boringssl && git fetch --depth=1 https://github.com/google/boringssl.git ${boringssl_commit_tag} && git reset --hard FETCH_HEAD
3232

3333
PATCH_COMMAND git apply ${patch_file} && git gc --aggressive
3434
PREFIX ${PROJECT_BINARY_DIR}

cmake/external/uWebSockets.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ if(TARGET uWebSockets OR NOT DOWNLOAD_UWEBSOCKETS)
1818
return()
1919
endif()
2020

21-
set(commit 4d94401b9c98346f9afd838556fdc7dce30561eb)
21+
set(uwebsockets_commit_tag 4d94401b9c98346f9afd838556fdc7dce30561eb)
22+
set(patch_file
23+
${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/uWebSockets/0001-fix-want-write-crash.patch)
2224

2325
ExternalProject_Add(
2426
uWebSockets
2527

26-
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
27-
DOWNLOAD_NAME uWebSockets-${commit}.tar.gz
28-
URL https://github.com/uNetworking/uWebSockets/archive/${commit}.tar.gz
28+
DOWNLOAD_COMMAND
29+
COMMAND git init uWebSockets
30+
COMMAND cd uWebSockets && git fetch --depth=1 https://github.com/uNetworking/uWebSockets.git ${uwebsockets_commit_tag} && git reset --hard FETCH_HEAD
2931

32+
PATCH_COMMAND git apply ${patch_file} && git gc --aggressive
3033
PREFIX ${PROJECT_BINARY_DIR}
31-
3234
CONFIGURE_COMMAND ""
3335
BUILD_COMMAND ""
3436
INSTALL_COMMAND ""

cmake/external_rules.cmake

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ function(download_external_sources)
121121
file(INSTALL "${PROJECT_SOURCE_DIR}/cmake/external/leveldb.cmake"
122122
DESTINATION "${PROJECT_BINARY_DIR}/external/src/firestore/cmake/external")
123123
endif()
124-
125-
execute_process(
126-
COMMAND ${FIREBASE_PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/patch_websockets.py"
127-
"-file" "${PROJECT_BINARY_DIR}/external/src/uWebSockets/src/Socket.h"
128-
"-cmakefile" "${PROJECT_SOURCE_DIR}/cmake/external/uWebSockets.cmake"
129-
RESULT_VARIABLE STATUS)
130-
if( STATUS AND NOT STATUS EQUAL 0 )
131-
message(FATAL_ERROR "FAILED to patch uWebsockets/src/Socket.h")
132-
message(FATAL_ERROR "see cmake/external_rules.cmake.")
133-
endif()
134124
endif()
135125
endfunction()
136126

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From d868ac6f2ce8c6ba8359e33616caeb889e0c57e7 Mon Sep 17 00:00:00 2001
2+
From: "google.com" <google.com>
3+
Date: Wed, 7 Jul 2021 19:00:49 -0400
4+
Subject: [PATCH] fix want_write crash
5+
6+
---
7+
src/Socket.h | 34 ++++++++++++++++++----------------
8+
1 file changed, 18 insertions(+), 16 deletions(-)
9+
10+
diff --git a/src/Socket.h b/src/Socket.h
11+
index 2179ff8..521e798 100644
12+
--- a/src/Socket.h
13+
+++ b/src/Socket.h
14+
@@ -306,24 +306,26 @@ protected:
15+
if (messageQueue.empty()) {
16+
17+
if (ssl) {
18+
- sent = SSL_write(ssl, message->data, message->length);
19+
- if (sent == (ssize_t) message->length) {
20+
- wasTransferred = false;
21+
- return true;
22+
- } else if (sent < 0) {
23+
- switch (SSL_get_error(ssl, sent)) {
24+
- case SSL_ERROR_WANT_READ:
25+
- break;
26+
- case SSL_ERROR_WANT_WRITE:
27+
- if ((getPoll() & UV_WRITABLE) == 0) {
28+
- setPoll(getPoll() | UV_WRITABLE);
29+
- changePoll(this);
30+
+ /* BEG Patched by firebase-cpp-sdk 00001-fix-want-write-crash.patch */
31+
+ bool continue_loop = true;
32+
+ do {
33+
+ sent = SSL_write(ssl, message->data, message->length);
34+
+ if (sent == (ssize_t) message->length) {
35+
+ wasTransferred = false;
36+
+ return true;
37+
+ } else if (sent < 0) {
38+
+ switch (SSL_get_error(ssl, sent)) {
39+
+ case SSL_ERROR_WANT_READ:
40+
+ continue_loop = false;
41+
+ break;
42+
+ case SSL_ERROR_WANT_WRITE:
43+
+ break;
44+
+ default:
45+
+ return false;
46+
}
47+
- break;
48+
- default:
49+
- return false;
50+
}
51+
- }
52+
+ } while (continue_loop);
53+
+ /* END Patched by firebase-cpp-sdk 00001-fix-want-write-crash.patch */
54+
} else {
55+
sent = ::send(getFd(), message->data, message->length, MSG_NOSIGNAL);
56+
if (sent == (ssize_t) message->length) {
57+
--
58+
2.32.0.93.g670b81a890-goog
59+

scripts/patch_websockets.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)