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

[OTP-19158][OTP-19221] whaileee/maint-25/inets/httpc_improvements #8788

Conversation

Whaileee
Copy link
Contributor

@Whaileee Whaileee commented Sep 6, 2024

No description provided.

@Whaileee Whaileee added the team:PS Assigned to OTP team PS label Sep 6, 2024
@Whaileee Whaileee self-assigned this Sep 6, 2024
@Whaileee Whaileee added the testing currently being tested, tag is used by OTP internal CI label Sep 6, 2024
@Whaileee
Copy link
Contributor Author

Whaileee commented Sep 6, 2024

This pr closes #8538

lib/inets/src/http_client/httpc.erl Outdated Show resolved Hide resolved
lib/inets/src/http_client/httpc_request.erl Outdated Show resolved Hide resolved
lib/inets/src/http_client/httpc_request.erl Outdated Show resolved Hide resolved
Comment on lines 886 to 895
unalias(ClientAlias),
receive
{http, {RequestId, {ok, saved_to_file}}} ->
{ok, saved_to_file};
{http, {RequestId, {error, Reason}}} ->
{error, Reason};
{http, {RequestId, {ok, {StatusLine,Headers,BinBody}}}} ->
Body = maybe_format_body(BinBody, Options),
{ok, {StatusLine, Headers, Body}};
{http, {RequestId, {ok, {StatusCode,BinBody}}}} ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unalias(ClientAlias),
receive
{http, {RequestId, {ok, saved_to_file}}} ->
{ok, saved_to_file};
{http, {RequestId, {error, Reason}}} ->
{error, Reason};
{http, {RequestId, {ok, {StatusLine,Headers,BinBody}}}} ->
Body = maybe_format_body(BinBody, Options),
{ok, {StatusLine, Headers, Body}};
{http, {RequestId, {ok, {StatusCode,BinBody}}}} ->
true = unalias(ClientAlias),
receive
{http, {RequestId, {ok, saved_to_file}}} ->
{ok, saved_to_file};
{http, {RequestId, {error, Reason}}} ->
{error, Reason};
{http, {RequestId, {ok, {StatusLine, Headers, BinBody}}}} ->
Body = maybe_format_body(BinBody, Options),
{ok, {StatusLine, Headers, Body}};
{http, {RequestId, {ok, {StatusCode, BinBody}}}} ->

Copy link
Contributor

github-actions bot commented Sep 6, 2024

CT Test Results

  2 files   21 suites   11m 29s ⏱️
334 tests 310 ✅ 23 💤 1 ❌
558 runs  519 ✅ 39 💤 0 ❌

For more details on these failures, see this check.

Results for commit fb19f1c.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@Whaileee Whaileee force-pushed the whaileee/maint-25/inets/httpc_improvements branch from 0ea1b80 to abf2130 Compare September 9, 2024 09:30
@Whaileee Whaileee changed the base branch from maint-25 to maint September 10, 2024 13:21
@Whaileee Whaileee changed the base branch from maint to maint-25 September 10, 2024 13:22
@@ -379,6 +379,12 @@
ReplyInfo}</c>.</p>
</item>

<tag><c>alias()</c></tag>
Copy link
Contributor

Choose a reason for hiding this comment

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

is alias() used in parallel to pid() now? or should alias replace pid?
if both are used, maye we should give some hint which one is used when ... or why and when alias is better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think alias should replace pid, as they are two separate datatypes, even if they serve a similar purpose. I believe that by looking up, or knowing what exactly alias is, end-user will be able to judge whether to use pid or alias.

@@ -1144,6 +1163,7 @@ request_options([{Key, DefaultVal, Verify} | Defaults], Options, Acc) ->
BodyFormat :: string() | binary() | atom(),
SocketOpt :: term(),
Receiver :: pid()
Copy link
Contributor

Choose a reason for hiding this comment

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

Receiver type is repeated several times in this module. Should it always include alias type (i.e. reference())?

Copy link
Contributor Author

@Whaileee Whaileee Sep 23, 2024

Choose a reason for hiding this comment

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

This is the new default for sync requests. Users have to specify the receiver when using {sync, false}.

Copy link
Contributor

Choose a reason for hiding this comment

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

You lost me, the alias should used for the sync request to ensure that you can time it out without the user process receiving a message that it does not expect. The alias should not be something that the user of the inets API is aware of.

cancel_request(RequestId),
unalias(ClientAlias),
receive
{http, {RequestId, {ok, saved_to_file}}} ->
Copy link
Contributor

Choose a reason for hiding this comment

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

write a code comment explaining why 2nd almost the same receive block is repeated in after Timeout?
is it supposed to handle some race condition? did you observe it in test runs?

why not give up and return error instantly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in case the message comes in after Timeout but before unalias, It ensures that the message queue doesn't contain junk that is unreachable.

case httpc_manager:request(Request, profile_name(Profile)) of
{ok, RequestId} ->
handle_answer(RequestId, Sync, Options);
handle_answer(RequestId, Receiver, Sync, Options,
element(#http_options.timeout, HTTPOptions));
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Comment on lines 1089 to 1090
(Value) when is_reference(Value) ->
ok;
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Comment on lines 885 to 900
cancel_request(RequestId),
unalias(ClientAlias),
receive
{http, {RequestId, {ok, saved_to_file}}} ->
{ok, saved_to_file};
{http, {RequestId, {error, Reason}}} ->
{error, Reason};
{http, {RequestId, {ok, {StatusLine, Headers, BinBody}}}} ->
Body = maybe_format_body(BinBody, Options),
{ok, {StatusLine, Headers, Body}};
{http, {RequestId, {ok, {StatusCode, BinBody}}}} ->
Body = maybe_format_body(BinBody, Options),
{ok, {StatusCode, Body}}
after 0 ->
{error, timeout}
end
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation (whole after block)

Comment on lines 1177 to 1178
Reference when is_reference(Reference) ->
ok;
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

@u3s
Copy link
Contributor

u3s commented Sep 17, 2024

PR title could be adjusted to be more meaningful

@Whaileee Whaileee force-pushed the whaileee/maint-25/inets/httpc_improvements branch 4 times, most recently from fd5fcc0 to 6f4c5e0 Compare September 24, 2024 08:37
@Whaileee Whaileee force-pushed the whaileee/maint-25/inets/httpc_improvements branch from 6f4c5e0 to 6c07478 Compare September 25, 2024 12:05
@Whaileee Whaileee force-pushed the whaileee/maint-25/inets/httpc_improvements branch from 4aaf71d to fb19f1c Compare September 26, 2024 14:12
@Whaileee Whaileee closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

httpc:request full_result option does not work in async mode
4 participants