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

[#397]: Preserve the order of the response messages when the stream response process handles ":consume_response" #396

Merged

Conversation

senconscious
Copy link
Contributor

@senconscious senconscious commented Jan 9, 2025

Fixes /issues/397

@senconscious senconscious changed the title Simple bug demonstration and bugfix Simple bug and bugfix demonstration for response ordering Jan 9, 2025
@@ -100,7 +100,7 @@ defmodule GRPC.Client.Adapters.Mint.StreamResponseProcess do
{{_, message}, rest} ->
# TODO add code here to handle compressor headers
response = codec.decode(message, res_mod)
new_responses = [{:ok, response} | responses]
new_responses = responses ++ [{:ok, response}]
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using a list, let's change the data structure to a queue: https://www.erlang.org/doc/apps/stdlib/queue.html

Erlang :queue is supposed to be O(1) for enqueueing and dequeueing. This change is O(len(responses)) for enqueueing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, migrated to erlang queue

@senconscious senconscious changed the title Simple bug and bugfix demonstration for response ordering Fix: Keep responses order when stream response process consumes response Jan 9, 2025
@senconscious senconscious marked this pull request as ready for review January 9, 2025 15:11
@senconscious senconscious changed the title Fix: Keep responses order when stream response process consumes response Fix: Preserve the order of the response messages when the stream response process handles "consume_response" Jan 9, 2025
@senconscious senconscious changed the title Fix: Preserve the order of the response messages when the stream response process handles "consume_response" Fix: Preserve the order of the response messages when the stream response process handles ":consume_response" Jan 9, 2025
@senconscious senconscious marked this pull request as draft January 9, 2025 15:21
@senconscious senconscious marked this pull request as ready for review January 9, 2025 15:25
@senconscious senconscious changed the title Fix: Preserve the order of the response messages when the stream response process handles ":consume_response" Fix: [#397] Preserve the order of the response messages when the stream response process handles ":consume_response" Jan 9, 2025
@senconscious senconscious changed the title Fix: [#397] Preserve the order of the response messages when the stream response process handles ":consume_response" [#397]: Preserve the order of the response messages when the stream response process handles ":consume_response" Jan 9, 2025
@polvalente polvalente merged commit 5c97c68 into elixir-grpc:master Jan 9, 2025
8 checks passed
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.

Response ordering must be guaranteered when streaming
2 participants