Skip to content
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
2 changes: 1 addition & 1 deletion src/minirest_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pmap_exec(CallerPid, Fun, El, Timeout) ->
ExecResult =
receive
{result, Pid, {normal, Result}} -> Result;
{result, Pid, {crash, {C, E, ST}}} -> erlang:raise(C, E, ST);
{result, Pid, {crash, {C, E, ST}}} -> {error, {El, {C, E, ST}}};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If pmap caller traps exits, then in case of crash it was stuck forever because:

  • the caller pid receives EXIT as a message
  • but it never handles it, because pmap_exec process crashes and timeout message is not sent, so pmap_gather waits forever.

{'DOWN', Ref, process, Pid, Reason} -> {error, {El, Reason}}
after Timeout ->
true = erlang:exit(Pid, kill),
Expand Down
38 changes: 38 additions & 0 deletions test/minirest_util_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%% Copyright (c) 2013-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.

-module(minirest_util_SUITE).

-compile(export_all).
-compile(nowarn_export_all).

-include_lib("stdlib/include/assert.hrl").

all() ->
[
t_pmap_exception
].

t_pmap_exception(_Config) ->
process_flag(trap_exit, true),
ct:timetrap({seconds, 2}),

?assertMatch(
[
{error, {a, {error, a, _}}},
{error, {b, {error, b, _}}},
{error, {c, {error, c, _}}}
],
minirest_util:pmap(fun(X) -> error(X) end, [a, b, c], 1000)
).