Skip to content
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

Revert json ops #2814

Merged
merged 3 commits into from
Aug 24, 2019
Merged

Revert json ops #2814

merged 3 commits into from
Aug 24, 2019

Conversation

ry
Copy link
Member

@ry ry commented Aug 24, 2019

We're experiencing odd benchmarks and errors as a result of the recent ops moving to JSON. They're odd because node and hyper benchmarks are being negatively effected along with deno.

It's disconcerting that the errors below did not cause the tests to fail.

Errors are seen during the benchmarks:

Compile file:///home/travis/build/denoland/deno/tools/deno_tcp.ts
Listening on 127.0.0.1:4544
Listening on 127.0.0.1:4545
error: Uncaught RangeError: start offset of Int32Array should be a multiple of 4
► js/dispatch_minimal.ts:44:17
    at asyncMsgFromRust (js/dispatch_minimal.ts:44:17)
    at asyncMsgFromRust$3 (js/dispatch.ts:57:7)
    at handleAsyncMsgFromRust (shared_queue.js:171:9)
Compile file:///home/travis/build/denoland/deno/js/deps/https/deno.land/std/http/http_bench.ts
http://127.0.0.1:4546/
Listening on http://127.0.0.1:4548
Compile file:///home/travis/build/denoland/deno/tools/deno_http_proxy.ts
Proxy listening on http://127.0.0.1:4547/
error: Uncaught RangeError: start offset of Int32Array should be a multiple of 4
► js/dispatch_minimal.ts:44:17
    at asyncMsgFromRust (js/dispatch_minimal.ts:44:17)
    at asyncMsgFromRust$3 (js/dispatch.ts:57:7)
    at handleAsyncMsgFromRust (shared_queue.js:171:9)
Listening on http://127.0.0.1:4550
Compile file:///home/travis/build/denoland/deno/tools/deno_tcp_proxy.ts
Proxy listening on http://127.0.0.1:4549/
single-thread
http_bench.js start
listening http://127.0.0.1:4544/ rid = 3
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)
unexpected err Connection reset by peer (os error 104)

cc @bartlomieju

@ry ry requested a review from piscisaureus August 24, 2019 19:34
Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubberstamp LGTM

@ry ry merged commit 2235dd7 into denoland:master Aug 24, 2019
@ry ry deleted the revert_json_ops branch August 24, 2019 20:21
@bartlomieju
Copy link
Member

bartlomieju commented Aug 25, 2019

@ry @piscisaureus I believe I figured out the cause of the problem, why it wasn't caught in the test and how to solve it.

Cause

The error specified below appears when there's a response for "minimal op" and shared buffer of shared_queue ends up with message that has a length that is not a multiple of 4.

error: Uncaught RangeError: start offset of Int32Array should be a multiple of 4
► js/dispatch_minimal.ts:44:17
    at asyncMsgFromRust (js/dispatch_minimal.ts:44:17)
    at asyncMsgFromRust$3 (js/dispatch.ts:57:7)
    at handleAsyncMsgFromRust (shared_queue.js:171:9)

This situation happens when there's a "json op" that pushes response onto shared queue and is subsequently followed by response of minimal op. That happens because buf from "json op" is not padded ("flatbuffer op" and "minimal op" responses are aligned to 4 bytes).

Tests

The tests did not catch that bug because it requires high concurrency - in unit test suite there are concurrent tests for net module but the concurrency is low (like 2 concurrent accepts). That means that shared_queue can be emptied and reset between response of "json op" and "minimal op" (which causes to reset the offset of shared buffer). That's why the error appears in http benchmark - it's a highly concurrent situation, before last connection is accepted the first connection already reads bytes - this makes it so there's response from "minimal op" and "json op" inside buffer of shared queue (first one is aligned to 4-bytes, while the second might not be).

Possible solution

The easiest solution that comes to mind is to ensure that response buffer from "json op" is aligned to 4-bytes. Additionally I believe that there should be a check in shared_queue.rs::push to ensure that all responses are aligned to 4-bytes.

EDIT: Proof-of-concept solution 7b9d07f

bartlomieju added a commit to bartlomieju/deno that referenced this pull request Aug 25, 2019
@bartlomieju bartlomieju mentioned this pull request Aug 25, 2019
@ry
Copy link
Member Author

ry commented Aug 25, 2019

@bartlomieju thank you for that analysis - it sounds very likely that you’ve figured it out! We should add a unit test to shared_queue.rs that demos pushing some non-aligned buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants