Skip to content

Commit

Permalink
Add repro for bitwalker/swarm#91
Browse files Browse the repository at this point in the history
  • Loading branch information
kzemek committed Jul 12, 2018
0 parents commit 0d5feff
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM elixir:1.6.6-alpine

RUN mkdir /app
WORKDIR /app
COPY . .
RUN mix do local.hex --force, deps.get, compile
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Swarm deadlock repro

This repository serves as a repro for bitwalker/swarm#91 .
To start reproducing, simply run:

```sh
docker-compose up --scale repro=5
```

This command will build a docker image with the compiled repro Elixir application,
and run 5 instances of the image. All the application does is start `Swarm` and
`Libcluster` with `Cluster.Strategy.Gossip` topology. A single process on each
node prints state of the local `Swarm.Tracker` process.
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '2'
services:
repro:
build: .
command: ['sh', '-c', 'iex --cookie mycookie --name "node@$$(hostname -i)" -S mix']

This comment has been minimized.

Copy link
@kzemek

kzemek Jul 12, 2018

Author Owner

$ has to be escaped in docker-compose.yml, otherwise docker-compose tries to substitute it

26 changes: 26 additions & 0 deletions lib/my_app.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule TrackerStateMonitor do
use Task, restart: :permanent

def start_link(_args) do
Task.start_link(fn ->
Stream.repeatedly(fn -> Process.sleep(5000) end)
|> Enum.each(fn _ ->
{state, _} = :sys.get_state(Swarm.Tracker)
IO.puts("Swarm.Tracker state: #{state}")
end)
end)
end
end

defmodule MyApp do
use Application

@impl Application
def start(_type, _args) do
Supervisor.start_link([
{Cluster.Supervisor,
[[local: [strategy: Cluster.Strategy.Gossip]], [name: MyApp.ClusterSupervisor]]},
{TrackerStateMonitor, []}
], strategy: :one_for_one)
end
end
29 changes: 29 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule MyApp.MixProject do
use Mix.Project

def project do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :sasl],
mod: {MyApp, []}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:libcluster, "~> 3.0"},
{:swarm, "~> 3.3"}
]
end
end

0 comments on commit 0d5feff

Please sign in to comment.