-
Notifications
You must be signed in to change notification settings - Fork 61
fix: coro-channel attempts to resume running thread #329
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
Conversation
|
Also added a test to catch those cases. Worth noting some... annoyances, while writing that test I noticed if the writer returns with Also, a |
|
As I expanded the tests I noticed another state-related bug, consider the following code: local ssocket = {
write = function(_, _, callback)
callback('callback failed')
return true
end,
is_closing = function()
return false
end
}
local write = require("coro-channel").wrapWrite(ssocket)
assert(write(""))The control flow of this goes something like this:
Usually, the This is now fixed by separating the call error from the callback error and tracked by two separate states. |
truemedian
left a comment
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.
In general I dislike the state that this change introduces, which makes it significantly harder to reason about what is happening in the control flow through these functions.
However if this fixes the bug I'm fine with introducing it and writing it off for "clean up later".
|
This likely won't be the last fix we introduce for a problem like this. I
also hate the complexity of this flow and it proved annoying as I got it
wrong the first 3 attempts. What should the flow look like ideally if you
happen to have an idea?
…On Mon, 30 Sept 2024, 16:39 truemedian, ***@***.***> wrote:
***@***.**** approved this pull request.
In general I dislike the state that this change introduces, which makes it
significantly harder to reason about what is happening in the control flow
through these functions.
However if this fixes the bug I'm fine with introducing it and writing it
off for "clean up later".
—
Reply to this email directly, view it on GitHub
<#329 (review)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJDIIYGIZBFGFYZ3SKW2ETDZZFIARAVCNFSM6AAAAABL6MZ5LOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMZXGU4TEMRWGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
@squeek502 should be ready for merge. |
Consider the following minimal-reproduction code:
This will produce the following error
This happens because the write call at coro-channel.lua#L148 returns immediately, the callback produced by
wait()is also called immediately, this callback will attempt to resume the current thread, but thecoroutine.yieldline has not yet been executed (since write finished instantly).This minimal example is basically what happens when a socket is wrapped with
secure-socket, which will attempt to optimize empty writes by returning immediately (in the flush function over here it will execute the callback and return early).Which leads to
https/wssrequests made by coro-net crash when code such asrequire'coro-http'.request("POST", "https://google.com", {}, "")is ran (secure-socket sees that we are trying to write an empty chunk for the payload, so it decides to just return early and immediately since such a write will be ignored by libuv anyways).The solution suggested in this PR is to basically keep track of when the thread has yielded, and if the wait callback is called before we reach yield, then we don't bother with resuming current thread and just return, similar to what we did with
coro-split.fixes #303.