Comments (5)
After a bit of a reading, a cicuit breaker seems like a good solution
from elixir-thrift.
Hi @sarat1669, the Thrift connection processes are very simple and represent the lifetime of a connection over the network. Usually you do not want to allow a network failure to propagate failures through your supervision tree. The supervision tree should be used to handle errors with internal state and logic because those should be locally recoverable errors. Therefore you would need a slightly different pattern.
If you want to leverage OTP to its fullest you could start the connection as temporary worker from another process that monitors and restarts it when needed, perhaps it would do some backoff if start_link
returns a (connect) error.
If you want to use a circuit breaker, you may wish to put that around the thrift service calls in the processes making requests as the connection error is not the only type of error you may wish to handle. For example timeouts, tapplicationexceptions or even specific service exceptions.
from elixir-thrift.
@fishcakez, The issue is when the connection is dropped, the process kills itself.
And that bubbles up the supervision tree.
I had to do some defensive programming to avoid this.
try do
Client.get_element(client, params)
catch
:exit, _ -> {:error, :internal_server_error}
end
And I had to trap exits:
def handle_info({:EXIT, _pid, {:error, :econnrefused}}, {breaker, _client}) do
BreakerBox.increment_error(breaker)
{:noreply, {breaker, nil}}
end
Which is not recommended in beam ecosystem.
from elixir-thrift.
The first one:
try do
Client.get_element(client, params)
catch
:exit, _ -> {:error, :internal_server_error}
end
is a valid use of a catch and not too defensive because you are expecting to handle this error and preventing it bubbling up. Likely you want to differentiate between timeouts and other errors. You can do this by matching on the _
portion.
For the second example:
def handle_info({:EXIT, _pid, {:error, :econnrefused}}, {breaker, _client}) do
BreakerBox.increment_error(breaker)
{:noreply, {breaker, nil}}
end
This seems like you are not using the directly supervisor anymore and starting the process underneath another one instead of using the temporary child under a supervisor I mentioned above.
from elixir-thrift.
@fishcakez, Makes sense. Yeah, I have wrapped it in a genserver.
And will add other parameters to the circuit breaking logic. Thanks for the info.
from elixir-thrift.
Related Issues (20)
- Split generated serde code from transport handling by introducing middlewares HOT 12
- IntegrationTest test failures
- Adopt the Mix.Task.Compiler behaviour
- ssl:ssl_accept/3: deprecated; use ssl:handshake/3 instead HOT 1
- Add support for a header based protocol
- Service tests fail to start child
- A typedef which references an included typedef fails to compile
- "Client exit" service test sometimes fails HOT 2
- Represent AST names using a list of atoms
- Spawn a process for each client request
- Debugging oneway calls HOT 3
- Support schema annotations to opt-in to copy strings out of the binary HOT 7
- Multiplexing Support HOT 1
- Difference with pinterest/riffed HOT 1
- Error: expected -> clauses for :rescue in "try" HOT 2
- RFC: Middleware framework HOT 1
- Buffered transport for binary protocol HOT 2
- Sharing modules across apps HOT 4
- Make thrift parser a separate package HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixir-thrift.