Просмотр исходного кода

Properly cancel timed-out queries from SSL connections

Formerly, we tried to use inet:peername/1 to determine where to
connect to issue the cancel command. This caused a crash when the
connection hosting the timed-out query was over SSL, since you must
call ssl:peername/1 for SSL sockets.

The crash looked like this:

[error] CRASH REPORT Process <0.25743.31> with 2 neighbours exited
with reason: no function clause matching
prim_inet:peername({sslsocket,{gen_tcp,#Port<0.667326>,
                    tls_connection},<0.25810.31>})
in gen_fsm:terminate/7 line 622
Phillip Calvin 10 лет назад
Родитель
Сommit
dcaa1126bc
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      src/epgsql_sock.erl

+ 6 - 2
src/epgsql_sock.erl

@@ -120,8 +120,12 @@ handle_cast({{Method, From, Ref}, Command} = Req, State)
 handle_cast(stop, State) ->
     {stop, normal, flush_queue(State, {error, closed})};
 
-handle_cast(cancel, State = #state{backend = {Pid, Key}}) ->
-    {ok, {Addr, Port}} = inet:peername(State#state.sock),
+handle_cast(cancel, State = #state{backend = {Pid, Key},
+                                   sock = TimedOutSock}) ->
+    {ok, {Addr, Port}} = case State#state.mod of
+                             gen_tcp -> inet:peername(TimedOutSock);
+                             ssl -> ssl:peername(TimedOutSock)
+                         end,
     SockOpts = [{active, false}, {packet, raw}, binary],
     %% TODO timeout
     {ok, Sock} = gen_tcp:connect(Addr, Port, SockOpts),