Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unlink and close port safely

  • Loading branch information...
commit adf3b66616557893e20ecce39172cc4872e3f1c3 1 parent 52a4c49
Tom Preston-Werner authored
Showing with 13 additions and 5 deletions.
  1. +13 −5 elibs/server.erl
18 elibs/server.erl
View
@@ -122,17 +122,25 @@ handle_upload_pack_impl(Sock, Host, Header) ->
stream_out(Port, Sock),
% close connections
- port_close(Port),
- ok = gen_tcp:close(Sock);
+ ok = gen_tcp:close(Sock),
+ safe_port_close(Port);
{error, closed} ->
+ ok = gen_tcp:close(Sock),
port_command(Port, "0000"),
- port_close(Port),
+ safe_port_close(Port),
ok;
{error, Reason} ->
error_logger:error_msg("Client closed socket because: ~p~n", [Reason]),
+ ok = gen_tcp:close(Sock),
port_command(Port, "0000"),
- port_close(Port),
- ok = gen_tcp:close(Sock)
+ safe_port_close(Port)
+ end.
+
+safe_port_close(Port) ->
+ unlink(Port),
+ try port_close(Port)
+ catch
+ _:_ -> ok
end.
handle_upload_pack_nosuchrepo(Sock, Repo) ->
Please sign in to comment.
Something went wrong with that request. Please try again.