> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/dpr/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/dpr/latest/troubleshooting/peer-stuck-down.md).

# Recovering a peer stuck in the "down" state

Diameter Proxy (DPR) maintains an in-memory set of peers reported as unavailable by the [endpoints_watcher](https://docs.cennso.com/components/dpr/latest/configuration/endpoints-watcher.md) service. A peer is added to this set when DPR receives a `POST /endpoint/<name>/down` request and removed when it receives a `POST /endpoint/<name>/up` request.

A peer may remain marked as down even after it becomes available again. This can happen, for example, if the `endpoints_watcher` service is unable to deliver the recovery (`up`) notification.

When a peer is incorrectly marked as down, DPR does not relay new requests to it. Newer versions of Diameter Proxy improve this behaviour. However, if you are using DPR version `1.2.2` or earlier, you may still encounter situations where DPR does not update the peer state in time.

This document explains how to resolve this situation at runtime.

## Inspect the current state

First of all, check if there are peers stuck in the `down` state. To do so, check the current list of unavailable peers from the DPR's perspective in the DPR remote console:

```bash
kubectl exec -it {DPR_POD_NAME} -n {NAMESPACE} -c dpr --  /opt/diameter_proxy/bin/diameter_proxy remote
```

List every peer currently marked as down:

```erlang
ets:tab2list(diameter_proxy_app:bad_peer_table()).
%% [] means no peer is marked as down.
%% [{<<"diameter-agent-host-a">>,<<"down">>}] means that peer is marked as down.
```

If you find a peer that is marked as "down" but is actually healthy, read the following two sections to learn how to resolve the issue.

## Fix using the HTTP API

The first method to remove the peer from the list of unavailable peers is the HTTP API. You can send an `up` event for the affected peer to DPR's HTTP API from inside the DPR container:

```bash
kubectl exec {DPR_POD_NAME} -n {NAMESPACE} -c dpr -- \
  curl -sS -XPOST http://127.0.0.1:8080/endpoint/{PEER_NAME}/up
```

The `{PEER_NAME}` must be the peer name exactly as configured in `diameter_proxy.realms`.

## Fix using the remote console

Alternatively, you can use the DPR's remote console to clear the peer from the list of unavailable peers:

```erlang
ets:delete(diameter_proxy_app:bad_peer_table(), <<"{PEER_NAME}">>).
```
