Skip to content

Commit 022f2ad

Browse files
authored
Fix broken short-circuit optimization for pubsub detection (#151)
This clause never matches, because if Y is "\r", then it's not followed by another "\r\n". It's not a bug but just a broken optimization. resp_class(<<"*", _, "\r\n$", X, Y, "\r\n", _/binary>>) when Y =:= $\r, X =/= $9; % Shorter than "subscribe" Fix it by splitting the function clause in two. Signed-off-by: Viktor Söderqvist <[email protected]>
1 parent ef2922e commit 022f2ad

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ered_command.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ get_response_class({redis_command, pipeline, Data}) ->
106106
%% If the command name ends in "subscribe", returns a tuple
107107
%% {CommandName, NumChannels}. Returns 'normal' otherwise.
108108
%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109-
resp_class(<<"*", _, "\r\n$", X, Y, "\r\n", _/binary>>)
110-
when Y =:= $\r, X =/= $9; % Shorter than "subscribe"
111-
Y =/= $\r, X > $1 orelse Y > $2 -> % Longer than "punsubscribe"
109+
resp_class(<<"*", _, "\r\n$", X, "\r\n", _/binary>>)
110+
when X =/= $9 -> % Shorter than "subscribe"
112111
normal; % Quick path for most commands.
112+
resp_class(<<"*", _, "\r\n$", X, Y, "\r\n", _/binary>>)
113+
when X > $1; Y > $2 -> % Longer than "punsubscribe"
114+
normal; % Quick path.
113115
resp_class(<<"*", N, "\r\n$9\r\n", _/binary>> = Subj) ->
114116
resp_class_helper(Subj, 8, 9, N - $0);
115117
resp_class(<<"*", N, "\r\n$1", X, "\r\n", _/binary>> = Subj)

0 commit comments

Comments
 (0)