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

Refactor the websocket handling in Nova #161

Merged
merged 7 commits into from Jan 16, 2022
Merged

Refactor the websocket handling in Nova #161

merged 7 commits into from Jan 16, 2022

Conversation

burbas
Copy link
Contributor

@burbas burbas commented Dec 30, 2021

I realized that the websocket plugins wouldn't work with the previous implementation so I sat down and rewrote parts of it. I also incorporated the handler-idea into websockets aswell.

The current implementation of websockets have a big flaw which will crash the flow if a post-plugin is used. This commits fix this aswell as integrating the websocket-flow in Novas generic way with handlers.
@burbas burbas requested a review from Taure December 30, 2021 12:39
@Taure
Copy link
Collaborator

Taure commented Dec 30, 2021

It looks ok, but I will test it with my test app and see if websocket works. :)

Copy link
Collaborator

@Taure Taure left a comment

Choose a reason for hiding this comment

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

> >  2021-12-30T14:14:19.693001+01:00 error: Ranch listener nova_listener had connection process started with cowboy_clear:start_link/4 at <0.2416.0> exit with reason: {function_clause,[{nova_ws_handler,terminate,[{crash,error,function_clause},#{host => <<"localhost">>,method => <<"GET">>,path => <<"/ws/wohoo">>,peer => {{127,0,0,1},58506},port => 8080,qs => <<>>,scheme => <<"http">>,version => 'HTTP/1.1'},{ok,#{controller_data => <<"wohoo">>,mod => nova_request_ws,module => nova_request_ws,plugins => [{pre_request,[{nova_request_plugin,#{decode_json_body => true,parse_qs => true,read_urlencoded_body => true}}]}]}}],[{file,"/home/daniel/project/nova_request_app/_build/default/lib/nova/src/nova_ws_handler.erl"},{line,67}]},{cowboy_websocket,handler_call,6,[{file,"/home/daniel/project/nova_request_app/_build/default/lib/cowboy/src/cowboy_websocket.erl"},{line,564}]},{cowboy_http,loop,1,[{file,"/home/daniel/project/nova_request_app/_build/default/lib/cowboy/src/cowboy_http.erl"},{line,257}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}```

Got a crash

@burbas
Copy link
Contributor Author

burbas commented Jan 15, 2022

@Taure Made a new commit on this. Updated our flow in how we are handling the result of a websocket-request. According to cowboy 2.7 the proper response is {commands(), State} (https://ninenines.eu/docs/en/cowboy/2.9/manual/cowboy_websocket/). So now we can send multiple frames/commands in one request (And plugins can also utilize this).

Copy link
Collaborator

@Taure Taure left a comment

Choose a reason for hiding this comment

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

Fix dialyzer warnings and we can merge this

@Taure Taure merged commit 8ce75f7 into master Jan 16, 2022
@Taure Taure deleted the websocket_plugins branch January 27, 2022 10:39
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.

None yet

2 participants