Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Fixed**

- Fix crashes due to missing error handling

## v0.6.0

**Security**
Expand Down
35 changes: 19 additions & 16 deletions lib/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,25 @@ defmodule Kadabra.Connection do
end

def init(%Config{} = config) do
{:ok, encoder} = Hpack.start_link()
{:ok, decoder} = Hpack.start_link()
{:ok, socket} = Socket.start_link(config.uri, config.opts)

config =
config
|> Map.put(:encoder, encoder)
|> Map.put(:decoder, decoder)
|> Map.put(:socket, socket)

state = initial_state(config)

Kernel.send(self(), :start)
Process.flag(:trap_exit, true)

{:ok, state}
with {:ok, encoder} <- Hpack.start_link(),
{:ok, decoder} <- Hpack.start_link(),
{:ok, socket} <- Socket.start_link(config.uri, config.opts) do
config =
config
|> Map.put(:encoder, encoder)
|> Map.put(:decoder, decoder)
|> Map.put(:socket, socket)

state = initial_state(config)

Kernel.send(self(), :start)
Process.flag(:trap_exit, true)

{:ok, state}
else
{:error, reason} ->
{:stop, reason}
end
end

defp initial_state(%Config{opts: opts, queue: queue} = config) do
Expand Down
8 changes: 6 additions & 2 deletions lib/connection_pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ defmodule Kadabra.ConnectionPool do

Process.flag(:trap_exit, true)

{:ok, connection} = Connection.start_link(config)
{:ok, %__MODULE__{connection: connection}}
with {:ok, connection} <- Connection.start_link(config) do
{:ok, %__MODULE__{connection: connection}}
else
{:error, reason} ->
{:stop, reason}
end
end

def handle_cast({:ask, demand}, state) do
Expand Down
4 changes: 2 additions & 2 deletions lib/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ defmodule Kadabra.Socket do
socket_send(socket, connection_preface())
{:ok, %__MODULE__{socket: socket}}

error ->
error
{:error, reason} ->
{:stop, reason}
end
end

Expand Down