Skip to content

Commit

Permalink
Merge pull request #4364 from esl/graphql_sse
Browse files Browse the repository at this point in the history
Fixing GraphQL SSE crash with large stanza payloads
  • Loading branch information
arcusfelis authored Aug 28, 2024
2 parents a82aa72 + 398fffd commit 3f2f4f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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))).

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

0 comments on commit 3f2f4f8

Please sign in to comment.