[thrift] better error handling and timeouts in tSocket code
Summary: default socket send timeout to 5seconds, not infinity.
close the socket in case of an error.
Reviewed By: cpiro
Test Plan: ran a client for slow services
and sanity checked other client code to make sure
Revert Plan: sure
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665504 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/transport/tSocket.erl b/lib/erl/src/transport/tSocket.erl
index 3af77c2..96b7aa9 100644
--- a/lib/erl/src/transport/tSocket.erl
+++ b/lib/erl/src/transport/tSocket.erl
@@ -71,9 +71,15 @@
effectful_open(This) ->
Host = oop:get(This, host),
Port = oop:get(This, port),
- Options = [binary, {packet, 0}, {active, false}, {reuseaddr, true},
- {nodelay, true}],
-
+ Options = [binary, {packet, 0},
+ {active, false},
+ {reuseaddr, true},
+ {nodelay, true},
+ {send_timeout, case application:get_env(thrift, socket_send_timeout) of
+ Millis when is_integer(Millis), Millis > 0 -> Millis;
+ _Else -> 5000
+ end}
+ ],
case gen_tcp:connect(Host, Port, Options) of
{error, _} ->
tException:throw(tTransportException,
@@ -90,7 +96,11 @@
Handle = oop:get(This, handle),
case gen_tcp:send(Handle, Data) of
+ {error,timeout} ->
+ effectful_close(This),
+ tException:throw(tTransportException, [?tTransportException_NOT_OPEN, "in write"]);
{error, _} ->
+ effectful_close(This),
tException:throw(tTransportException, [?tTransportException_NOT_OPEN, "in write"]);
ok ->
{ok, This}