Browse Source

Merge pull request #58 from pnc/peername-crash

Properly cancel timed-out queries from SSL connections
David N. Welton 10 years ago
parent
commit
673d4b2854
1 changed files with 6 additions and 2 deletions
  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) ->
 handle_cast(stop, State) ->
     {stop, normal, flush_queue(State, {error, closed})};
     {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],
     SockOpts = [{active, false}, {packet, raw}, binary],
     %% TODO timeout
     %% TODO timeout
     {ok, Sock} = gen_tcp:connect(Addr, Port, SockOpts),
     {ok, Sock} = gen_tcp:connect(Addr, Port, SockOpts),