diff options
author | 2023-09-15 21:18:57 -0700 | |
---|---|---|
committer | 2023-09-15 21:18:57 -0700 | |
commit | b54e3f3c042bc37418a646728428910cafc502ef (patch) | |
tree | f36f52c715300c6dd37add073fe76931cc98ab2d /packages | |
parent | 7f2e40af46bdd21984b9df1695895c7f43aba482 (diff) | |
download | bun-b54e3f3c042bc37418a646728428910cafc502ef.tar.gz bun-b54e3f3c042bc37418a646728428910cafc502ef.tar.zst bun-b54e3f3c042bc37418a646728428910cafc502ef.zip |
fix(corking) uncork if needed (#5525)
* fix size limit
* uncork if needed instead of terminating
* undo unrelated changes
Diffstat (limited to 'packages')
-rw-r--r-- | packages/bun-uws/src/AsyncSocket.h | 11 | ||||
-rw-r--r-- | packages/bun-uws/src/Loop.h | 6 | ||||
-rw-r--r-- | packages/bun-uws/src/LoopData.h | 1 |
3 files changed, 10 insertions, 8 deletions
diff --git a/packages/bun-uws/src/AsyncSocket.h b/packages/bun-uws/src/AsyncSocket.h index 8e3301f24..1051271a2 100644 --- a/packages/bun-uws/src/AsyncSocket.h +++ b/packages/bun-uws/src/AsyncSocket.h @@ -121,18 +121,25 @@ public: void corkUnchecked() { /* What if another socket is corked? */ getLoopData()->corkedSocket = this; + getLoopData()->corkedSocketIsSSL = SSL; } /* Cork this socket. Only one socket may ever be corked per-loop at any given time */ void cork() { /* Extra check for invalid corking of others */ if (getLoopData()->corkOffset && getLoopData()->corkedSocket != this) { - std::cerr << "Error: Cork buffer must not be acquired without checking canCork!" << std::endl; - std::terminate(); + // We uncork the other socket early instead of terminating the program + // is unlikely to be cause any issues and is better than crashing + if(getLoopData()->corkedSocketIsSSL) { + ((AsyncSocket<true> *) getLoopData()->corkedSocket)->uncork(); + } else { + ((AsyncSocket<false> *) getLoopData()->corkedSocket)->uncork(); + } } /* What if another socket is corked? */ getLoopData()->corkedSocket = this; + getLoopData()->corkedSocketIsSSL = SSL; } /* Returns the corked socket or nullptr */ diff --git a/packages/bun-uws/src/Loop.h b/packages/bun-uws/src/Loop.h index 6c7bdfc9e..d3ca45b58 100644 --- a/packages/bun-uws/src/Loop.h +++ b/packages/bun-uws/src/Loop.h @@ -58,12 +58,6 @@ private: for (auto &p : loopData->postHandlers) { p.second((Loop *) loop); } - - /* After every event loop iteration, we must not hold the cork buffer */ - if (loopData->corkedSocket) { - std::cerr << "Error: Cork buffer must not be held across event loop iterations!" << std::endl; - std::terminate(); - } } Loop() = delete; diff --git a/packages/bun-uws/src/LoopData.h b/packages/bun-uws/src/LoopData.h index 986bf0cbd..92bd9ffff 100644 --- a/packages/bun-uws/src/LoopData.h +++ b/packages/bun-uws/src/LoopData.h @@ -98,6 +98,7 @@ public: char *corkBuffer = new char[CORK_BUFFER_SIZE]; unsigned int corkOffset = 0; void *corkedSocket = nullptr; + bool corkedSocketIsSSL = false; /* Per message deflate data */ ZlibContext *zlibContext = nullptr; |