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

Removed detach #576

Merged
merged 7 commits into from
Dec 13, 2019
Merged

Removed detach #576

merged 7 commits into from
Dec 13, 2019

Conversation

MarcusLongmuir
Copy link
Contributor

@MarcusLongmuir MarcusLongmuir commented Oct 11, 2019

This PR removes the detach function and selectively replaces its usage.

The detach function was used to isolate user-provided callbacks from the rest of the grpc-web such that exceptions thrown by user-provided callbacks would not be caught by grpc-web. It called the user-provided callbacks inside a setTimeout call to prevent the catching of exceptions from the callback function. In my own usage of grpc-web with fake transports and alike this proved frustrating due to the disconnected stack trace caused by the setTimeout.

The function was also overused as a protective measure inside transports and that usage has been removed completely.

The usages that wrapped user-provided callbacks have been replaced by a try+catch that uses setTimeout to re-throw the exception if the callback throws one, but otherwise will execute the callback immediately.

This is a breaking change.

Usage that assumed the callbacks provided to grpc-web would be executed in a deferred manner could be broken by this change. This is unlikely to affect production code as the network request will always be asynchronous and would cause the callback to be invoked sometime in the future, but tests that assume other code will run between the grpc-web invocation and the callback being called could be affected.

@jonny-improbable
Copy link
Contributor

@MarcusLongmuir what is the status of this PR? I recall you mentioning it may improve performance, is that still the case?

@jonny-improbable jonny-improbable added the waiting-on-submitter Waiting on original poster action label Nov 2, 2019
@MarcusLongmuir MarcusLongmuir changed the title WIP - Removed detach Removed detach Nov 6, 2019
@MarcusLongmuir
Copy link
Contributor Author

@jonny-improbable: I've just managed to get this passing tests and it's now ready for review.

@@ -233,6 +246,7 @@ describe("FakeTransportBuilder", () => {
const onEndSpy = jest.fn();

const transport = new FakeTransportBuilder()
.withManualTrigger()
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated line.

@@ -20,6 +21,7 @@ describe("FakeTransportBuilder", () => {
it("should allow the response trailers to be stubbed", done => {
const expectedTrailers = new grpc.Metadata({ foo: "bar" });
const transport = new FakeTransportBuilder()
.withManualTrigger()
Copy link
Contributor

@jonny-improbable jonny-improbable Nov 6, 2019

Choose a reason for hiding this comment

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

I see you've made it be a manual trigger, but I don't see you triggering it anywhere in the test? I don't follow, you please explain this change?

@@ -258,8 +272,6 @@ describe("FakeTransportBuilder", () => {

transport.sendHeaders();

// Note that we must defer the assertions as the grpc-web package detaches all callbacks, so they
// will not run immediately.
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You've removed the comment, but not the timeout :)

@jonny-improbable jonny-improbable merged commit cd3cae9 into master Dec 13, 2019
@jonny-improbable jonny-improbable deleted the remove-detach branch December 13, 2019 07:37
@galenwarren
Copy link

Hi guys -- first, thanks for your work on this library, it's great!

I was having an issue where I would occasionally get errors logged in the console associated with connections that were being closed and which were also receiving data from a (server) streaming grpc call at the same time. It doesn't happen all the time but does happen frequently when those conditions are met, maybe a race condition of some sort? Not sure.

Here's an example of the error logged in the browser console:

VM11014:1 POST https://realurlreplaced net::ERR_FAILED 200
(anonymous) @ VM11014:1
e.send @ grpc-web-client.umd.js?ba3e:1
e.sendMessage @ grpc-web-client.umd.js?ba3e:1
e.send @ grpc-web-client.umd.js?ba3e:1
t.invoke @ grpc-web-client.umd.js?ba3e:1

To try to figure out what was going on, I cloned the repo. Using the code in the master branch, I can't reproduce the error, whereas I can reproduce it consistently with the 0.12.0 code.

Looking at the commits in master since 0.12.0, this looks like the potentially relevant change.

So, I wanted to let you know this latest code seems to be addressing my issue -- thanks! -- and also to ask whether you're considering releasing this code anytime soon?

@MarcusLongmuir
Copy link
Contributor Author

@galenwarren: We've just released 0.13.0 from latest master so you should be good to update to that to resolve the issue. Thanks for the prompt as it had been missed that this change hadn't gone out 👍

@galenwarren
Copy link

Awesome -- thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-submitter Waiting on original poster action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants