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

add more flexible support for long running callback handlers #52

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

andymck
Copy link

@andymck andymck commented Feb 25, 2021

Linked grpcbox_plugin PR: tsloughter/grpcbox_plugin#15

These changes originate from use cases encountered at helium and in integrating this lib into the helium stack.

NOTE: This PR introduces breaking changes for any existing services. Handlers would be required to be updated. I suspect this may be a blocker for this PR, however I am keen to hear thoughts. If it is a blocker I can recut a separate PR with only the necessary changes ( supporting props & maps in the service definitions )

The changes here have been tested as part of the helium stack and using another erlang grpc client from Bluehouse Technology.

Change Summary

  • Dont spawn off streaming RPC handlers and instead handle server side incoming msgs within the stream process. This allows for ( albeit a somewhat subjective opinion ) better structured handlers which can more easily maintain their own state. Obviously it also has the benefit of reducing the overall process count for each stream and removes the overhead in managing the spawned process ( such as handling their various exit signals ) and in exchanging msgs between the stream and spawned handler process.

  • Allow application callback handlers to define, initialize & maintain their own state within the context of the grpcbox stream. Thread state to all handler calls.

  • Allow info messages to be threaded from stream to application callback handlers.

  • Handle PB service names as either maps or props

TODO:

  • update interop tests

@andymck
Copy link
Author

andymck commented Mar 1, 2021

putting to draft until i get tests regressions addressed

@andymck andymck marked this pull request as draft March 1, 2021 15:40
@codecov
Copy link

codecov bot commented Mar 2, 2021

Codecov Report

Merging #52 (ba03e7c) into main (22d7a09) will increase coverage by 0.98%.
The diff coverage is 64.00%.

❗ Current head ba03e7c differs from pull request most recent head 1c5c9fb. Consider uploading reports for the commit 1c5c9fb to get more accurate results

@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
+ Coverage   37.83%   38.82%   +0.98%     
==========================================
  Files          28       28              
  Lines        2080     2102      +22     
==========================================
+ Hits          787      816      +29     
+ Misses       1293     1286       -7     
Impacted Files Coverage Δ
src/grpcbox_stream.erl 60.10% <46.87%> (-4.45%) ⬇️
src/grpcbox_services_sup.erl 90.66% <83.33%> (-0.89%) ⬇️
src/grpcbox_reflection_service.erl 97.36% <100.00%> (+0.22%) ⬆️
src/grpcbox_client.erl 57.14% <0.00%> (-2.02%) ⬇️
src/grpcbox_client_stream.erl 69.33% <0.00%> (ø)
src/grpcbox_oc_stats_handler.erl 58.33% <0.00%> (+58.33%) ⬆️
src/grpcbox_oc_stats.erl 62.50% <0.00%> (+62.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22d7a09...1c5c9fb. Read the comment docs.

@andymck
Copy link
Author

andymck commented Mar 2, 2021

@tsloughter I am curious to get your views on this change, mainly in relation to handling msgs in the stream context as opposed to spawning a new process.

As noted above it is a breaking change ( maybe i can resolve that but at this point not sure )....honestly I am not sure where this lib is in its life cycle and its usage in the erlang community. Maybe a breaking change is an absolute blocker, maybe you just dont like this approach or maybe you think it has some legs. Anyway appreciate any thoughts you have on this.

Base automatically changed from master to main March 22, 2021 19:49
@andymck andymck force-pushed the andymck/ts-master/stream-handler-changes branch from 09e244f to d21c1ac Compare May 6, 2021 12:06
@andymck andymck force-pushed the andymck/ts-master/stream-handler-changes branch 2 times, most recently from bdd8694 to 550c2b6 Compare May 23, 2021 18:53
@andymck andymck force-pushed the andymck/ts-master/stream-handler-changes branch from 9f777ad to 5698251 Compare July 27, 2021 15:28
@tsloughter
Copy link
Owner

Did you run into some issues with shutdown or socket closing that led to your most recent commit?

@andymck andymck force-pushed the andymck/ts-master/stream-handler-changes branch from 244bd9b to da0ec1e Compare August 11, 2021 16:57
@andymck
Copy link
Author

andymck commented Aug 11, 2021

@tsloughter We were seeing the grpcbox_socket process go down sporadically, and during init it would fail to restart as it hit eaddrinuse. The only scenario in which I can reproduce locally is by killing the process and forcing terminate to be bypassed. If this happens the server will fail to restart and end up breaking the sup restart strategy ( which was default, 1, 5), rending grpcbox effectively down.

I cannot determine at this point why the process might be being killed in the wild. Logs only indicate an enotconn error as being the earliest event which in itself should not be a problem.

I suspect there is more going on, but the blunt fix above gets things up and running again and keeps users connected

@andymck andymck force-pushed the andymck/ts-master/stream-handler-changes branch from 41daec2 to b92d38b Compare August 12, 2021 09:30
@jeffgrunewald jeffgrunewald force-pushed the andymck/ts-master/stream-handler-changes branch from 3f2f30a to 9ed629c Compare May 16, 2022 22:27
@jeffgrunewald jeffgrunewald force-pushed the andymck/ts-master/stream-handler-changes branch from 9ed629c to acc70e0 Compare May 16, 2022 23:27
@jeffgrunewald jeffgrunewald force-pushed the andymck/ts-master/stream-handler-changes branch from acc70e0 to 1c5c9fb Compare May 16, 2022 23:33
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