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

Fixing GraphQL SSE crash with large stanza payloads #4364

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion big_tests/tests/graphql_sse_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ all() ->
groups() ->
[{admin, [parallel], admin_tests()},
{user, [parallel], user_tests()},
{timeout, [], [sse_should_not_get_timeout]}].
{timeout, [parallel], [sse_should_not_get_timeout, sse_works_with_long_messages]}].

init_per_suite(Config) ->
Config1 = escalus:init_per_suite(Config),
Expand Down Expand Up @@ -148,6 +148,17 @@ sse_should_not_get_timeout(Config) ->
sse_helper:stop_sse(Stream)
end).

sse_works_with_long_messages(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun (Alice, Bob) ->
From = escalus_client:full_jid(Bob),
To = escalus_client:short_jid(Alice),
{200, Stream} = graphql_helper:execute_user_command_sse(<<"stanza">>, <<"subscribeForMessages">>, Alice, #{}, Config),
Message = binary:copy(<<"0">>, 2000),
escalus:send(Bob, escalus_stanza:chat(From, To, Message)),
sse_helper:wait_for_event(Stream),
sse_helper:stop_sse(Stream)
end).

%% Helpers

get_graphql_user_listener() ->
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/mongoose_graphql_response.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
-export([term_to_json/1, term_to_pretty_json/1]).

term_to_json(Term) ->
jiffy:encode(fixup(Term)).
iolist_to_binary(jiffy:encode(fixup(Term))).

Check warning on line 6 in src/graphql/mongoose_graphql_response.erl

View check run for this annotation

Codecov / codecov/patch

src/graphql/mongoose_graphql_response.erl#L6

Added line #L6 was not covered by tests
JanuszJakubiec marked this conversation as resolved.
Show resolved Hide resolved

term_to_pretty_json(Term) ->
jiffy:encode(fixup(Term), [pretty]).
iolist_to_binary(jiffy:encode(fixup(Term), [pretty])).

%% Ground types
fixup(Term) when is_number(Term) -> Term;
Expand Down