HelloZeroNet / HelloZeroNet/ZeroNet

deletion of false orphans at startup when appending --ui_ip '*'

未关闭
#2,846 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
18.8k
派生
2.3k
PR 合并指标
30 天内没有已合并 PR

描述

### Step 1: Please describe your environment

* ZeroNet version: 0.6.5
* Operating system: Void Linux 6.6.21_1
* Web browser: Chromium
* Tor status: disabled
* Opened port: no
* Special configuration: Old Laptop running on single core. Problem only appears when starting with --ui_ip '*'

### Step 2: Describe the problem:
In coherence to the description on github, i was able to start zeronet with the webfrontend available for other hosts inside the LAN by the "./ZeroNet.sh --ui_ip '*'" command, which works fine so far, but if i start a zeronet instance with --ui_ip '*' the instance always deletes orphaned zites (likely all cached zites) at startup. They are certainly not really orphans. And it doesn't delete false orphans when i start the instance with only "./ZeroNet.sh". By the description on github too, --ui_ip '*' has nothing to do with deleting orphaned zites, and without --ui_ip '*' i cannot access the webfrontend from other hosts. The latter (turning on availability of webfrontend from other hosts) is in line with the description and desired behavior, but the former (deleting orphans) is unexpected and undesired.

I asked huggingchat with web search enabled if he can provide more detail what is happening here, maybe by reviewing the source code of Zeronet on github. I found the answer quite interesting and i assume his diagnose might be really related (as the host where i run the instance is rather old laptop running in single core mode due to thermal problems), so i paste it below:

After investigating the source code of ZeroNet on Github, I found the location where the --ui_ip option is processed: <[https://github.com/HelloZERO/ZeroNet/blob/master/src/zeronet.py#L249>](https://github.com/HelloZERO/ZeroNet/blob/master/src/zeronet.py#L249). As expected, it binds the UI to all interfaces when set to '*'. This option should not directly affect the deletion of orphaned sites.

After further investigation, I discovered that the deletion of orphaned sites occurs during initialization of the SiteManager class, specifically within its cleanup_orphaned() method call (<[https://github.com/HelloZERO/ZeroNet/blob/master/src/zeronet/site_manager.py#L310>](https://github.com/HelloZERO/ZeroNet/blob/master/src/zeronet/site_manager.py#L310)).

When ZeroNet starts up, it initializes the SiteManager, which then calls the cleanup_orphaned() function to remove unreferenced files. It checks for "zite" folders under the data directory that aren't referenced anymore by active torrents. In simple terms, these could be considered as "orphaned." If the number of such directories exceeds the limit defined in ORPHANED_SITES_CLEARUP_LIMIT, they will be removed upon starting ZeroNet.

The reason why the orphaned sites are being cleaned up when running with --ui_ip '*' is likely due to differences in timing between regular operation and the one with the specified ui_ip parameter. When started with --ui_ip '*', additional setup time is required because the HTTP server needs to bind to all interfaces. During this extended initialization process, the SiteManager finishes initializing earlier than usual, allowing the cleanup routine to run before new sites get added to the system.

In conclusion, although the --ui_ip '*' flag does not explicitly delete orphaned sites, the difference in initialization times caused by binding the UI to all interfaces indirectly leads to orphaned site removal. To avoid the accidental deletion of your sites, ensure that the network connection is stable while launching ZeroNet so that the site loading sequence aligns better with the initialization order.
#### Steps to reproduce:

1. start Zeronet with the command ./ZeroNet.sh --ui_ip '*' and watch the output at startup
2. start Zeronet with the command ./ZeroNet.sh and watch the output at startup
3. compare the outputs at startup

#### Observed Results:
multiples of the following line at startup:
[] SiteManager Deleting orphan site from content.db: [site-string]

#### Expected Results:
not deleting false orphans

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先比较 ./ZeroNet.sh --ui_ip '*' 和 ./ZeroNet.sh 的启动输出,重点关注重复出现的孤立站点消息。检查 src/zeronet.py 中 --ui_ip 处理部分附近的代码,以及 src/zeronet/site_manager.py 中 cleanup_orphaned() 附近的代码。完成的标准是能够复现报告中的问题,并防止在使用 --ui_ip '*' 时删除有效站点。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。