Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base node libtor does not clean up temporary files on exit #6739

Closed
leet4tari opened this issue Jan 13, 2025 · 4 comments · Fixed by #6782
Closed

base node libtor does not clean up temporary files on exit #6739

leet4tari opened this issue Jan 13, 2025 · 4 comments · Fixed by #6782
Assignees

Comments

@leet4tari
Copy link
Contributor

Running minotari_node on Linux creates files in /tmp folder, looks to be tor related and does not clean up after exit.

root@efe92d8f38bb:/work/unzip# ls -la /tmp/
total 20
drwxrwxrwt 1 root root 4096 Jan 13 12:59 .
drwxr-xr-x 1 root root 4096 Jan 13 12:47 ..
-rw-r----- 1 root root   64 Jan 13 12:59 .tmpbzfa2h
drwx------ 3 root root 4096 Jan 13 12:59 .tmplItJDU
root@efe92d8f38bb:/work/unzip# cat /tmp/.tmpbzfa2h
Jan 13 12:59:34.000 [notice] Tor 0.4.7.13 opening new log file.
root@efe92d8f38bb:/work/unzip# ls -la /tmp/.tmplItJDU/
total 20
drwx------ 3 root root 4096 Jan 13 12:59 .
drwxrwxrwt 1 root root 4096 Jan 13 12:59 ..
-rw------- 1 root root   21 Jan 13 12:59 control_port
drwx------ 2 root root 4096 Jan 13 12:59 keys
-rw------- 1 root root    0 Jan 13 12:59 lock
-rw------- 1 root root  203 Jan 13 12:59 state

Even cleaning out tari folder and running with libtor disabled:
./minotari_node -b ./tari/ --disable-splash-screen -p use_libtor=false

Still find new temporary files and folder after exit.

Expected behavior
Temporary files should be deleted on exit. This becomes a problem with disk space be used by files that are not need. Becomes a big problem, if base node is re-started often.

Desktop (please complete the following information):

  • OS & Version: Ubuntu 24.04.1 LTS
  • Tari suite Version: tari_suite-1.9.2-pre.0-98a76e5-linux-arm64
@leet4tari
Copy link
Contributor Author

Example of /tmp folder after a few restarts

root@efe92d8f38bb:/work/unzip# du -ch /tmp/.tmp*
4.0K	/tmp/.tmp0ukolz
4.0K	/tmp/.tmpJjoB7K/keys
12M	/tmp/.tmpJjoB7K
4.0K	/tmp/.tmpUdKxTx/keys
16K	/tmp/.tmpUdKxTx
4.0K	/tmp/.tmpXL75rO/keys
16K	/tmp/.tmpXL75rO
4.0K	/tmp/.tmphwcrco
4.0K	/tmp/.tmpn6w7JO/keys
24M	/tmp/.tmpn6w7JO
4.0K	/tmp/.tmpof73ki
4.0K	/tmp/.tmpq6YAU7/keys
2.8M	/tmp/.tmpq6YAU7
4.0K	/tmp/.tmptc7tje
4.0K	/tmp/.tmpxchcn8
38M	total

@leet4tari
Copy link
Contributor Author

This looks to be happening on OSX too, but is a little hard to find the OSX tmp folder

leet@leet-tari-m1pro ~ % ls -lda /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmp*
-rw-r-----@ 1 leet  staff   64 Jan 13 17:15 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmp1nrsh4
drwx------@ 9 leet  staff  288 Jan 13 17:31 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmp6rSJH4
drwx------@ 9 leet  staff  288 Jan 13 13:31 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmpHbCj7d
drwx------@ 9 leet  staff  288 Jan 13 17:15 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmpZjBRMK
-rw-r-----@ 1 leet  staff   64 Jan 13 17:17 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmpjvzhaa
-rw-r-----@ 1 leet  staff   64 Jan 13 13:30 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmprmg0ss

I found this by running minotari_node, then finding the PID of minotari_node. Using the PID then checked all open files held by the PID and looking for anything that starts with /.tmp/

leet@leet-tari-m1pro ~ % lsof -p 75377 |grep -i "/.tmp"
minotari_ 75377 leet   21w     REG               1,16       64            66802070 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmpjvzhaa
minotari_ 75377 leet   22u     REG               1,16        0            66802072 /private/var/folders/_1/tdmqc6vx5lqc1syjyfmll7t40000gn/T/.tmp6rSJH4/lock

@leet4tari
Copy link
Contributor Author

These files created in the /tmp or related folder in OSX, seem to be hard coded and not controllable by the user. Would be nice if the user had some control over the name and location, so that clean up and be more controlled for more custom setups, like where a /tmp is not writable by the user would break running.

root@efe92d8f38bb:/work/unzip# ./minotari_node -b ./tari/ --disable-splash-screen -p use_libtor=false
Initializing logging according to "./tari/esmeralda/config/base_node/log4rs.yml"
ExitError { exit_code: IOError, details: Some("No such file or directory (os error 2) at path \"/tmp/.tmpSe6dfT\"") }
13:32 ERROR Exiting with code (108): ExitError { exit_code: IOError, details: Some("No such file or directory (os error 2) at path \"/tmp/.tmpSe6dfT\"") }

@hansieodendaal
Copy link
Contributor

See #6782 - the PR only covered libtor temporary files

SWvheerden pushed a commit that referenced this issue Feb 5, 2025
Description
---
The base node and console wallet have various immediate exit paths
through 'process::exit', as well as controlled exit via user/shutdown
command.

- This implementation ~~uses a unique but predictable handshake file
containing the libtor temporary directory for each base node or console
wallet running instance to cover all exit paths. When the main thread
exits, via user command or 'process::exit', the libtor temporary files
and the handshake file are removed.~~ does away with the temporary
libtor data folder and log file and instead uses a fixed or
user-controllable location via the `--libtor-data-dir` command line
option.

- ~~Added libtor exiting logic to:~~
  - ~~log any shutdown errors;~~
  - ~~remove temporary files.~~
- Added a failsafe timeout for test-liveness.

Closes #6739 and #6741

Motivation and Context
---
See #6739 and #6741

How Has This Been Tested?
---
System-level testing:
- Base node (Ubuntu), executing test liveness from the command line,
with and without using libtor
```
./minotari_node --base-path $(realpath .) --log-config $(realpath ./config)/log4rs_node.yml --network esmeralda --disable-splash-screen -p esmeralda.p2p.seeds.dns_seeds= -p esmeralda.p2p.seeds.peer_seeds= --watch "test-peer-liveness f6186e6f15af070d01d5aec8c5a53d81088c34b777cd0b25292d1cd522532462 /onion3/5uqpxi6ando6jrtcpj3aok4z7ab2nm36knfv2pzdf2hefdpkdcjnazid:18141 true true false" --non-interactive-mode -p base_node.use_libtor=true
```
- Base node (Ubuntu), with console, using libtor
- Console wallet (Ubuntu), with console, using libtor
- Console wallet (Ubuntu), recovery into console, using libtor

What process can a PR reviewer use to test or verify this change?
---
System-level testing
Code review

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants