RPC: FIX leak - adaptation in Resto and RPC middleware
What
Fixing leak of file descriptors when External RPC process is used, see the doc:
Why
The leak of FDs was caused by 3 bugs:
- EOF was not read on the External RPC process as the handler is busy with handling of streamed requests, like /monitor/heads/main
- RPC middleware was not notified when a client dies. Missing functionality in Tezos code which is easy to introduce
- Cohttp was not closing client-side connection on request in Tezos use case: on relay connections
How
Resto changes:
- adaptation to close_fn provided by Cohttp
- providing sleep_fn to Cohttp to get notified on EOF from peer for a client-side connection
RPC middleware:
- providing a
close_conncallback for a client-side connection to be notified on EOF - adaptation to close_fn provided by Cohttp
Manually testing the MR
Described in RPC UX: Resto, Cohttp and Lwt_stream usage
In terminal 1:
TEZOS_LOG="*->debug" CONDUIT_TLS=native CONDUIT_DEBUG=true COHTTP_DEBUG=true DATA_DIR=/tmp/lapin ./src/bin_node/octez-sandboxed-node.sh 1 --connections 0 2>&1 | grep -v quota
If you are running it for the first time, stop it, edit file /tmp/lapin/config.json, then start again:
- "listen-addrs": ["127.0.0.1:18731"]
+ "external-listen-addrs": ["127.0.0.1:18731"]
If you run it multiple times and something weird happens, change the folder /tmp/lalpin to something else. E.g. /tmp/lapin1.
When the external RPC process is started, it prints a trace:
starting RPC server on ::ffff:127.0.0.1:18731 (acl = AllowAll)
In terminal 2:
eval `./src/bin_client/octez-init-sandboxed-client.sh 1`
octez-activate-alpha
curl 'localhost:18731/monitor/heads/main'
Curl will wait for the new blocks until it is stopped.
In terminal 3:
lsof -a -U -c main.exe ; lsof -a -i -c main.exe | grep -v -e CLOSE_WAIT -e CLOSED ; lsof -a -i -c curl
Again in terminal 2:
Ctrl+C // to stop curl
If the test is passed, you will see traces in terminal 1 about EOF, conn_closed() callbacks called by Cohttp, Resto and RPC middleware. Now, if you run lsof again, you will see that the connections created for curl are released in Tezos node and External RPC process.
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR