-
Notifications
You must be signed in to change notification settings - Fork 226
Websocket lifecycle fixes #2411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stephenberry
wants to merge
7
commits into
main
Choose a base branch
from
websocket
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
110a6d0
Websocket lifecycle fixes
stephenberry 2910dec
Synchronous handshake
stephenberry 94d2884
Perform TCP connect, SSL handshake, and HTTP upgrade synchronously on…
stephenberry 6af2f51
Remove broken background thread
stephenberry dc83bee
IOCP patch
stephenberry 4b03013
Guard iocp patch for WIN32
stephenberry 53ac469
Verify iocp fix
stephenberry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ CMakeUserPresets.json | |
| **/CMakeCache.txt | ||
| **/Testing/ | ||
|
|
||
| # Claude Code | ||
| .claude/ | ||
|
|
||
| # IDE files | ||
| .idea/ | ||
| .vs/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Patch for ASIO issue #312: IOCP out-of-resources error reporting. | ||
| # https://github.com/chriskohlhoff/asio/issues/312 | ||
| # | ||
| # When PostQueuedCompletionStatus fails due to resource exhaustion, the | ||
| # completion key (overlapped_contains_result) is lost. The operation falls | ||
| # back to an internal queue but do_one() dispatches it with the wrong | ||
| # error code and bytes_transferred, causing undefined behavior / crashes. | ||
| # | ||
| # Fix: store the completion key on the operation object before posting, | ||
| # so it survives the fallback path. | ||
| # | ||
| # Based on MongoDB's patch: | ||
| # https://github.com/mongodb-forks/asio/commit/d03c2e7002131305645374e735a8ece4191f2fc5 | ||
|
|
||
| function(apply_asio_iocp_fix asio_include_dir) | ||
| set(OP_HEADER "${asio_include_dir}/asio/detail/win_iocp_operation.hpp") | ||
| set(CTX_IMPL "${asio_include_dir}/asio/detail/impl/win_iocp_io_context.ipp") | ||
|
|
||
| if(NOT EXISTS "${OP_HEADER}" OR NOT EXISTS "${CTX_IMPL}") | ||
| message(WARNING "ASIO IOCP fix: headers not found at ${asio_include_dir}, skipping patch") | ||
| return() | ||
| endif() | ||
|
|
||
| # Check if already patched (look for our added member) | ||
| file(READ "${OP_HEADER}" op_content) | ||
| if(op_content MATCHES "completionKey_") | ||
| message(STATUS "ASIO IOCP fix: already applied") | ||
| return() | ||
| endif() | ||
|
|
||
| message(STATUS "Applying ASIO IOCP fix (issue #312)") | ||
|
|
||
| # --- Patch win_iocp_operation.hpp --- | ||
| # Add completionKey_ member and accessor | ||
|
|
||
| # Add member after "long ready_;" | ||
| string(REPLACE | ||
| "long ready_;" | ||
| "long ready_;\n ULONG_PTR completionKey_;" | ||
| op_content "${op_content}") | ||
|
|
||
| # Initialize in constructor: find "ready_(0)" and add completionKey_(0) | ||
| string(REPLACE | ||
| "ready_(0)" | ||
| "ready_(0), completionKey_(0)" | ||
| op_content "${op_content}") | ||
|
|
||
| # Add accessor method before the "private:" or "protected:" section | ||
| # Find "func_type func_;" and add the accessor before the member block | ||
| string(REPLACE | ||
| "win_iocp_operation* next_;" | ||
| "ULONG_PTR& completionKey() { return completionKey_; }\n\n win_iocp_operation* next_;" | ||
| op_content "${op_content}") | ||
|
|
||
| file(WRITE "${OP_HEADER}" "${op_content}") | ||
|
|
||
| # --- Patch win_iocp_io_context.ipp --- | ||
| file(READ "${CTX_IMPL}" ctx_content) | ||
|
|
||
| # Fix post_deferred_completion: pass op->completionKey() instead of 0 for the key | ||
| # Original: PostQueuedCompletionStatus(iocp_.handle, 0, 0, op) | ||
| # Fixed: PostQueuedCompletionStatus(iocp_.handle, 0, op->completionKey(), op) | ||
| string(REPLACE | ||
| "::PostQueuedCompletionStatus(iocp_.handle, 0, 0, op)" | ||
| "::PostQueuedCompletionStatus(iocp_.handle, 0, op->completionKey(), op)" | ||
| ctx_content "${ctx_content}") | ||
|
|
||
| # Fix on_pending/on_completion: store key on op before posting | ||
| # Original pattern: | ||
| # if (!::PostQueuedCompletionStatus(iocp_.handle, | ||
| # 0, overlapped_contains_result, op)) | ||
| # Fixed pattern: | ||
| # op->completionKey() = overlapped_contains_result; | ||
| # if (!::PostQueuedCompletionStatus(iocp_.handle, | ||
| # 0, op->completionKey(), op)) | ||
| string(REPLACE | ||
| "if (!::PostQueuedCompletionStatus(iocp_.handle,\n 0, overlapped_contains_result, op))" | ||
| "op->completionKey() = overlapped_contains_result;\n if (!::PostQueuedCompletionStatus(iocp_.handle,\n 0, op->completionKey(), op))" | ||
| ctx_content "${ctx_content}") | ||
|
|
||
| file(WRITE "${CTX_IMPL}" "${ctx_content}") | ||
|
|
||
| message(STATUS "ASIO IOCP fix applied successfully") | ||
| endfunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all of this works, it will be necessary to add checks to ensure that the Windows OS