Commits

Oscar Hellström committed aa6564e

Make sure the manager doesn't get sockets it doeesn't own.

Comments (0)

Files changed (1)

src/lhttpc_client.erl

         {ok, R, NewSocket} ->
             % The socket we ended up doing the request over is returned
             % here, it might be the same as Socket, but we don't know.
+			% I've noticed that we don't want to give send sockets that we
+			% can't change the controlling process for to the manager. This
+			% really shouldn't fail, but it could do if:
+			% * The socket was closed remotely already 
+			% * Due to an error in this module (giving back dead sockets for
+			%   instance)
             ManagerPid = whereis(lhttpc_manager),
-            % If this fails, we're still the owner and the socket is closed
-            % when we exit, which is fine.
-            lhttpc_sock:controlling_process(NewSocket, ManagerPid, Ssl),
-            gen_server:cast(lhttpc_manager, {done, Host, Port, Ssl, NewSocket}),
+            case lhttpc_sock:controlling_process(NewSocket, ManagerPid, Ssl) of
+				ok ->
+					gen_server:cast(lhttpc_manager,
+						{done, Host, Port, Ssl, NewSocket});
+				_ ->
+					ok
+			end,
             {ok, R};
         {error, Reason} ->
             {error, Reason}