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

[Breaking Issue] Dictionary in config.yaml file doesn't follow order after preprocessing #1862

Open
5 of 6 tasks
MNDIA opened this issue Oct 23, 2024 · 5 comments
Open
5 of 6 tasks
Labels
C: Backend T: Bug Something isn't working

Comments

@MNDIA
Copy link
Contributor

MNDIA commented Oct 23, 2024

复现步骤 / Step to reproduce

A config.yaml file with nameserver-policy attribute.
image

预期行为 / Expected behavior

Keeping the text of the dictionary in order

实际行为 / Actual behavior

Dictionaries are treated as logical structures, unordered. This leads to chaotic rules for DNS. For example, dns loopbacks, or huge delays due to wrong parsing order

应用日志 / App logs

No response

备注 / Addition details

Dictionaries are unordered logical structures in the yaml syntax. But the actual configuration effect does not treat it as unordered. MetaCubeX/mihomo#1598 The order of the dictionaries in the mihomo configuration file for yaml is important

环境信息 / Environment information

Nyanpasu 1.6.1

自查步骤 / Verify steps

  • 如果您有足够的时间和能力,并愿意为此提交 PR,请勾上此复选框 / Pull request is welcome. Check this if you want to start a pull request
  • 您已知悉如果没有提供正确的系统信息,以及日志,您的 Issue 会直接被关闭 / You have known that if you don't provide correct system information and logs, your issue will be closed directly
  • 您已仔细查看并知情 Q&AFAQ 中的内容 / You have read and understood the contents of Q&A and FAQ
  • 您已搜索过 Issue Tracker,没有找到类似内容 / I have searched on Issue Tracker, No duplicate or related open issue has been found
  • 您确保这个 Issue 只提及一个问题。如果您有多个问题报告,烦请发起多个 Issue / Ensure there is only one bug report in this issue. Please make multiply issue for multiply bugs
  • 您确保已使用最新 Pre-release 版本测试,并且该问题在最新 Pre-release 版本中并未解决 / This bug have not solved in latest Pre-release version
@MNDIA MNDIA added S: Untriaged T: Bug Something isn't working labels Oct 23, 2024
@MNDIA MNDIA changed the title [Breaking Issue] Dictionaries in config.yaml file don't follow order after preprocessing [Breaking Issue] Dictionary in config.yaml file doesn't follow order after preprocessing Oct 23, 2024
@MNDIA
Copy link
Contributor Author

MNDIA commented Oct 23, 2024

The problem has been pinpointed in backend\tauri\src\enhance\mod.rs

 //检查点1:字典顺序正常
 // 内建脚本最后跑
    if enable_builtin {
        let mut script_runner = RunnerManager::new();
        for item in ChainItem::builtin()
            .into_iter()
            .filter(|(s, _)| s.contains(*clash_core.as_ref().unwrap_or(&ClashCore::default())))
            .map(|(_, c)| c)
        {
            log::debug!(target: "app", "run builtin script {}", item.uid);

            if let ChainTypeWrapper::Script(script) = item.data {
                let (res, _) = script_runner
                    .process_script(&script, config.to_owned())
                    .await;
                match res {
                    Ok(res_config) => {
                        config = res_config;
                    }
                    Err(err) => {
                        log::error!(target: "app", "builtin script error `{err:?}`");
                    }
                }
            }
        }
    }
  //检查点2:字典顺序混乱

The execution of this part will cause the dictionary of config to be disordered

@greenhat616
Copy link
Collaborator

Maybe the cause is the deserialization of table from lua.

What's more, why mihomo use the order of a map, which is mostly implemented as a hashmap?

@MNDIA
Copy link
Contributor Author

MNDIA commented Oct 23, 2024

It may be that dictionaries are written with fewer parentheses than arrays, or perform better

@greenhat616
Copy link
Collaborator

I glanced at the document. The mlua don't provide a helper to resolve this issue. So in current situation, we should implement a diff algorithm to resort the map key order according to original one recursively.

@MNDIA
Copy link
Contributor Author

MNDIA commented Oct 23, 2024

If using lua preprocessing on the mihomo core, the sorting problem needs to be solved from algorithm.
For now, quickly solve the usage problem with js instead, simply avoiding lua. DNS policy affects internet access very badly

greenhat616 added a commit that referenced this issue Oct 26, 2024
…to mihomo limitation (#1866)

[1]#1862 Fix DNS policy order for mihomo
1.  Just don't touch lua for mihomo core. JS processing can maintain dictionary order.
This way, at least for now, it works fine when users are not using their own lua for processing.
2.  Preserve todo for lua defects

[2]#1819 Support group hidden display for mihomo
1.   `hidden` wasn't working.
2.   The `hidden` decision should be present at all times, so fixed the logic hole

[3]#1864 Fix one-click installation service on windows
1.  `wmic` utility may be deprecated or not installed in newer versions of Windows



Solved some very critical usage issues,  it's time to update a release. Please point out if anything is inappropriate


COMMIT HISTORY:

* Ditch lua's default processing, switch to js

* prettier

* Fix hidden logic when deferredProxiesFilter doesn't exist

* Fix issue with getting current user SID on Windows

* Keep todo markfor the root cause of the problem

* Add fallback for new version of windows

* Keep the sid method and fix it in the upstream

* chore: correct fronend code styles

---------

Co-authored-by: Jonson Petard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Backend T: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants