-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
http/websocket: fix mid-size frames sometimes failing to be received #197
Open
LBPHacker
wants to merge
1
commit into
daurnimator:master
Choose a base branch
from
LBPHacker:fix-websocket-midsize-read-fail
base: master
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 all commits
Commits
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
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -243,23 +243,62 @@ describe("http.websocket module two sided tests", function() | |
assert.truthy(cq:empty()) | ||
end) | ||
local function send_receive_test(name, data, data_type) | ||
it(name, function() | ||
data_type = data_type or "text" | ||
local cq = cqueues.new() | ||
local c, s = new_pair() | ||
cq:wrap(function() | ||
assert(c:send(data, data_type)) | ||
assert.same({data, data_type}, {assert(c:receive())}) | ||
assert(c:close()) | ||
local function do_test(bad_connection) | ||
local bname = name | ||
if bad_connection then | ||
bname = bname .. ", even if the connection is really bad" | ||
end | ||
it(bname, function() | ||
data_type = data_type or "text" | ||
if bad_connection then | ||
local real_xwrite | ||
local fragments = 100 | ||
local delay = 1 / fragments -- Aim for 1s. | ||
real_xwrite = cs.interpose("xwrite", function(self, str, mode, timeout) | ||
if mode ~= "bn" then -- Not interesting, don't throttle. | ||
return real_xwrite(self, str, mode, timeout) | ||
end | ||
local deadline | ||
if timeout then | ||
deadline = cqueues.monotime() + timeout | ||
end | ||
local ok, op, why | ||
local nbytes = math.ceil(#str / fragments) | ||
local before_first = 0 | ||
repeat | ||
-- Test range at the end to ensure that real_xwrite is called at least once. | ||
-- We rely on the fact here that :sub sanitizes the input range. | ||
ok, op, why = real_xwrite(self, str:sub(before_first + 1, before_first + nbytes), mode, deadline and (deadline - cqueues.monotime())) | ||
if not ok then | ||
break | ||
end | ||
before_first = before_first + nbytes | ||
cqueues.sleep(delay) | ||
until before_first > #str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be |
||
return ok, op, why | ||
end) | ||
finally(function() | ||
cs.interpose("xwrite", real_xwrite) | ||
end) | ||
end | ||
local cq = cqueues.new() | ||
local c, s = new_pair() | ||
cq:wrap(function() | ||
assert(c:send(data, data_type)) | ||
assert.same({data, data_type}, {assert(c:receive())}) | ||
assert(c:close()) | ||
end) | ||
cq:wrap(function() | ||
assert.same({data, data_type}, {assert(s:receive())}) | ||
assert(s:send(data, data_type)) | ||
assert(s:close()) | ||
end) | ||
assert_loop(cq, TEST_TIMEOUT) | ||
assert.truthy(cq:empty()) | ||
end) | ||
cq:wrap(function() | ||
assert.same({data, data_type}, {assert(s:receive())}) | ||
assert(s:send(data, data_type)) | ||
assert(s:close()) | ||
end) | ||
assert_loop(cq, TEST_TIMEOUT) | ||
assert.truthy(cq:empty()) | ||
end) | ||
end | ||
do_test(false) | ||
do_test(true) | ||
end | ||
send_receive_test("works with small size frames", "f") | ||
send_receive_test("works with medium size frames", ("f"):rep(200)) | ||
|
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.
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.
You don't need to interpose the whole library: you should be able to overwrite just the specific instance:
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.
It just seemed like the intended way to do it, but sure, I could do that.
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.
Ah never mind, I remember now why I did it like this. CQS sockets are userdata, you can't just override their methods like that.
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.
I'm open to alternatives.