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

client stream callbacks #127

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

tsloughter
Copy link
Collaborator

This patch makes it so a callback module can be defined for clients to handle streaming responses. I am using this for building client support in https://github.com/tsloughter/grpcbox

I think there still needs to be updates to how it keeps the response body the way it does in the close stream record when the callback is undefined, but I'm not sure yet what would be a better solution, if there is one.

I also removed the no longer used static content handler.

I'll fix up the removal of warnings as errors in another PR, which will probably get in before this one, so it can be added back soon in this PR.

@tsloughter tsloughter force-pushed the client-cb branch 2 times, most recently from f9f15ba to 9dad094 Compare June 19, 2018 18:42
@tsloughter
Copy link
Collaborator Author

I ended up including the fix for OTP-21 warnings in this, so ignore that from my original comment.

true ->
erlang:apply(Mod, Fun, AllArgs);
false ->
{ok, State}
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure why this isn't an error? in what case would a callback function specified not exist but not be an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The user doesn't have to support every callback from h2_stream. Maybe they should, or at least some f them, but I just went with not requiring any stream handling callback being required from the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@getong
Copy link

getong commented Jun 28, 2018

@tsloughter
handshake/[1,2] always returns a new socket.
The functions might be changed like this:

-ifdef(OTP_RELEASE).
ssl_accept(ClientSocket, SSLOptions) ->
    ssl:handshake(ClientSocket, SSLOptions).
-else.
ssl_accept(ClientSocket, SSLOptions) ->
  case ssl:ssl_accept(ClientSocket, SSLOptions) of
     ok ->
          {ok, ClientSocket};
     {error, Reason} ->
          {error, Reason}
  end.
-endif.

and other function must handle the returned result.

@tsloughter
Copy link
Collaborator Author

@getong chatterbox was already using ssl_accept this way, I figure we leave it as is since it is also the deprecated function.

@rslota
Copy link
Contributor

rslota commented Jul 10, 2018

@tsloughter Could you please make a separate PR with the ssl_accept fix? Since this PR is quite big, it may not be merged very soon, while the ssl_accept deprecation prevents this project from being built on Erlang 21.0 (warning_as_error that as far as I know cannot be disabled by mix in top level project).

@tsloughter
Copy link
Collaborator Author

Sure.

tsloughter and others added 7 commits May 27, 2019 14:23
When remote HTTP server is down, in h2_connection:init/1 Transport:connect will return econnrefused. As this call is handled in h2_connection:init/1, current code returns {stop,econnrefused}. Although this is handled gracefully by clients, we do see an CRASH report saying that:

`[error] CRASH REPORT Process <0.2985.0> with 0 neighbours exited with reason: econnrefused in gen_statem:init_result/6 line 728`

gen_statem:init origin routine would have called exit with a reason code other than normal and this triggers the CRASH report. If the gen_statem client has returned ignore, the gen_statem process would have exited with exit(normal) and will not trigger this CRASH
When remote HTTP server is down, in h2_connection:init/1 Transport:connect will return econnrefused. As this call is handled in h2_connection:init/1, current code returns {stop,econnrefused}. Although this is handled gracefully by clients, we do see an CRASH report saying that:

`[error] CRASH REPORT Process <0.2985.0> with 0 neighbours exited with reason: econnrefused in gen_statem:init_result/6 line 728`

gen_statem:init origin routine would have called exit with a reason code other than normal and this triggers the CRASH report. If the gen_statem module has returned {stop, {shutdown,Reason}}, the gen_statem process would call Module:terminate/1 and exit appropriately without a crash report.
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.

5 participants